使用代碼替換文件夾中文本文件的一組字符。有一種方法可以爲文件夾中的所有文件執行此操作。我正在使用Windows 7操作系統和Powershell版本3.附加我擁有的代碼。問題是,當我運行代碼(New_NOV_1995.txt)時它會創建一個新文件,但它不會像代碼中所述那樣更改新文件中的任何字符。非常感謝幫助。Windows Powershell替換文件夾中文本文件的一組字符
$lookupTable = @{
'¿' = '|'
'Ù' = '|'
'À' = '|'
'Ú' = '|'
'³' = '|'
'Ä' = '-'
}
$original_file = 'C:\FilePath\NOV_1995.txt'
$destination_file = 'C:\FilePath\NOV_1995_NEW.txt'
Get-Content -Path $original_file | ForEach-Object {
$line = $_
$lookupTable.GetEnumerator() | ForEach-Object {
if ($line -match $_.Key)
{
$line = $line -replace $_.Key, $_.Value
}
}
$line
} | Set-Content -Path $destination_file
在第一行中使用'Get-ChildItem'而不是'Get-Content'。 –