我有一個腳本,重新命名從CSV採取的文件,但是當它改掉,重新命名文件後,它已經進行了成功的proceedure重命名從CSV腳本重命名文件,但改掉重複過程
它拋出一個錯誤CSV文件是這樣的:
old new
AC100 DC100
AC101 DC102
代碼嘗試:
$sourceDir = read-host "Please enter source Dir:"
$csvL = $sourceDir + "\files.csv"
$csv = import-csv $csvL
$files = get-childitem $sourceDir
$csv | % {
ForEach($file in $files){
if($file = $_.old){
$old = $sourceDir + "\" + $_.old
Rename-Item $old $_.new
}
}
}
我相信這是值得做的循環和CSV但林不知道在哪裏我去錯了,我之前有類似的問題。
以下是錯誤的示例。
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
Rename-Item : Cannot rename because item at 'C:\scripts\2039X.67438.TXT' does not exist.
At C:\scripts\renamerTim.ps1:18 char:15
+ Rename-Item <<<< $old $_.new
在此先感謝, 克雷格
它扔了什麼錯誤? – Rynant
if($ file = $ _。old)也許是if($ file -eq $ _。old)。發佈你的錯誤.. –