不清楚你的实际文件/情况,仅以问题中的说明及猜测为据
复制粘贴到记事本,另存为xx
.bat,编码选ANSI<# :
cls
@echo off
rem 将多个txt文本文件里的指定内容/固定内容替换成文件所在的目录名+文件名
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@% %z%
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%~dp0'"
echo;%#% +%$%%$%/%@% %z%
pause
exit
#>
$folder='.';
$findword='111';
$enc=[Text.Encoding]::Default;
$files=@(dir -liter $folder -recurse|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
for($i=0;$i -lt $files.length;$i++){
write-host $files[$i].Name;
$oldtext=[IO.File]::ReadAllText($files[$i].FullName, $enc);
$newtext=$oldtext.replace($findword, $files[$i].Directory.Name+'/'+$files[$i].Name);
[IO.File]::WriteAllText($files[$i].FullName, $newtext, $enc);
};