使用代码替换文件夹中文本文件的一组字符。有一种方法可以为文件夹中的所有文件执行此操作。我正在使用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'。 –