有人能告诉我为什么这个脚本不起作用吗?为什么不重命名文件? Powershell
Get-ChildItem "\\fhnsrv01\home\aborgetti\Documentation\Stage" -Filter *.EDIPROD | `
Foreach-Object{
$content = Get-Content $_.FullName
#filter and save content to a new file
$content | Where-Object {$_ -match 'T042456'} | Rename-Item `
($_.BaseName+'_834.txt')
我在这里发现了另一个问题的这种语法并更改了环境变量。
由于某些原因,它不会更改文件的名称。文件名是
'AIDOCCAI.D051414.T042456.MO.EDIPROD'
非常感谢。
UPDATE
感谢TheMadTechnician我能得到一些工作的东西。好的东西其实。图我应该与世界分享!
#Call Bluezone to do file transfer
#start-process "\\fhnsrv01\home\aborgetti\Documentation\Projects\Automation\OpenBZ.bat"
#Variable Declarations
$a = Get-Date
$b = $a.ToString('MMddyy')
$source = "\\fhnsrv01\home\aborgetti\Documentation\Stage\"
$dest = "\\fhnsrv01\home\aborgetti\Documentation\Stage\orig"
#Find all the files that have EDIPROD extension and proceed to process them
#First copy the original file to the orig folder before any manipulation takes place
Copy-item $source\*.EDIPROD $dest
# Now we must rename the items that are in the table
Switch(GCI \\fhnsrv01\home\aborgetti\Documentation\Stage\*.EDIPROD){
{(GC $_|Select -first 1) -match "834*"}{$_ | Rename-Item -NewName {$_.BaseName+'_834.txt'}}
{(GC $_|Select -first 1) -match "820*"}{$_ | Rename-Item -NewName {$_.BaseName+'_820.txt'}}
}
你想做什么?只需重命名文件? –
我想看看有.EDIPROD的后缀,这些文件的符合条件的那些需要用的834后缀和.TXT – Hituptony
你检查我的回答一个文件名类型重命名的文件。它为你工作。 – Rahul