各位大佬,谁能帮我写个bat指令,删除文件里的x0y0z0,
bat吧
全部回复
仅看楼主
level 2
各位大佬,谁能帮我写个bat指令,删除文件里的x0y0z0,只删除第三行的这个,多个文件同时删除,
2020年03月01日 00点03分 1
level 2
2020年03月01日 00点03分 2
level 9
不清楚你的实际文件/情况,仅以问题中的样例/说明为据
复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起运行
@璐村惂鐢ㄦ埛_000076K馃惥 off
rem 删除多个文本文件里指定行中的指定字符串内容
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@璐村惂鐢ㄦ埛_053Q95e馃惥 %z%
cd /d "%~dp0"
set "newfolder=%~dp0#result"
if not exist "%newfolder%" (md "%newfolder%")
powershell -NoProfile -ExecutionPolicy bypass ^
$n=3;$enc=[Text.Encoding]::Default;^
$files=@(dir -liter '%~dp0'^|?{('.bat' -ne $_.Extension) -and ($_ -is [System.IO.FileInfo])});^
for($i=0;$i -lt $files.length;$i++){^
write-host ('['+($i+1)+']'+$files[$i].Name);^
$text=[IO.File]::ReadAllLines($files[$i].FullName, $enc);^
if($n -lt $text.count){$text[$n-1]=$text[$n-1].replace('X0 Y0 Z0','');};^
[IO.File]::WriteAllLines('%newfolder%\'+$files[$i].Name, $text, $enc);^
};
:end
echo;%#% +%$%%$%/%@% %z%
pause
exit
2020年03月01日 08点03分 3
level 2
谢谢[真棒]
2020年03月03日 06点03分 4
level 13
@qop_dob 不知道混编怎么写比较好,我以前用的是:
<# @ rem 2>nul
@ copy /y %0 %tmp%\%~n0.ps1
@ powershell -ExecutionPolicy RemoteSigned -File %tmp%\%~n0.ps1
@ del /f /q %tmp%\%~n0.ps1
@ exit /b
#>
2020年03月03日 06点03分 5
level 9
@贴吧用户_0KSaNSR
<# :
cls
@璐村惂鐢ㄦ埛_000076K馃惥 off
cd /d "%~dp0"
powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default)))"
pause
exit
#>
write-host '#'*32;
2020年03月03日 15点03分 6
用IO.File是因为Get-Content慢吗?
2020年03月03日 23点03分
@贴吧用户_0KSaNSR 不,为了版本兼容问题
2020年03月04日 06点03分
@qop_dob 还有这个坑?
2020年03月04日 07点03分
1