发布网友 发布时间:2022-04-24 05:02
共2个回答
热心网友 时间:2023-10-30 13:06
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据
复制粘贴到记事本,另存为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);
};
热心网友 时间:2023-10-30 13:06
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d /b /s *.txt') do (
set "filename=%%~a"
set "filename=!filename:%~dp0=!"
(for /f "usebackq delims=" %%b in ("%%~a") do (
set "line=%%~b"
call :getline "!filename!"
echo.!line!
))>#
move # "%%~a"
)
goto :eof
:getline
set "line=!line:111=%~1!"
热心网友 时间:2023-10-30 13:06
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据
复制粘贴到记事本,另存为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);
};
热心网友 时间:2023-10-30 13:06
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d /b /s *.txt') do (
set "filename=%%~a"
set "filename=!filename:%~dp0=!"
(for /f "usebackq delims=" %%b in ("%%~a") do (
set "line=%%~b"
call :getline "!filename!"
echo.!line!
))>#
move # "%%~a"
)
goto :eof
:getline
set "line=!line:111=%~1!"
热心网友 时间:2023-10-30 13:06
不清楚你的实际文件/情况,仅以问题中的说明及猜测为据
复制粘贴到记事本,另存为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);
};
热心网友 时间:2023-10-30 13:06
@echo off&setlocal enabledelayedexpansion
for /f "delims=" %%a in ('dir /a-d /b /s *.txt') do (
set "filename=%%~a"
set "filename=!filename:%~dp0=!"
(for /f "usebackq delims=" %%b in ("%%~a") do (
set "line=%%~b"
call :getline "!filename!"
echo.!line!
))>#
move # "%%~a"
)
goto :eof
:getline
set "line=!line:111=%~1!"