不清楚你的实际文件/情况,仅以问题中的说明及猜测为据;以下代码复制粘贴到记事本,另存为xx.bat,编码选ANSI
<# :
cls&echo off&cd /d "%~dp0"
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
rem 替换nc文件里的指定内容
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$oldfolder="D:\NC";
$newfolder=$oldfolder.trimend("\")+"\result";
if(-not (test-path -literal $oldfolder)){write-host ('"'+$oldfolder+'" 未找到');exit;}
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
$files=@(dir -literal $oldfolder|?{(".nc" -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
$enc=[Text.Encoding]::GetEncoding('GB2312');
$text=[IO.File]::ReadAllText($files[0].FullName, $enc);
$text=$text.replace("G43 Z0. H00", "G43 Z2. H00");
$newfile=$newfolder.trimend("\")+"\"+$files[0].Name;
[IO.File]::WriteAllText($newfile, $text, $enc);
<# :
cls&echo off&cd /d "%~dp0"
set #=Any question&set _=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%_% %z%
rem 替换nc文件里的指定内容
powershell -NoProfile -ExecutionPolicy bypass "[IO.File]::ReadAllText(\"%~f0\",[Text.Encoding]::GetEncoding('GB2312'))|Invoke-Expression"
echo;%#% +%$%%$%/%_% %z%
pause
exit
#>
$oldfolder="D:\NC";
$newfolder=$oldfolder.trimend("\")+"\result";
if(-not (test-path -literal $oldfolder)){write-host ('"'+$oldfolder+'" 未找到');exit;}
if(-not (test-path -literal $newfolder)){[void][IO.Directory]::CreateDirectory($newfolder);}
$files=@(dir -literal $oldfolder|?{(".nc" -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
$enc=[Text.Encoding]::GetEncoding('GB2312');
$text=[IO.File]::ReadAllText($files[0].FullName, $enc);
$text=$text.replace("G43 Z0. H00", "G43 Z2. H00");
$newfile=$newfolder.trimend("\")+"\"+$files[0].Name;
[IO.File]::WriteAllText($newfile, $text, $enc);