批处理,文件名取后五位,前面拼O插入到文件第二行
bat吧
全部回复
仅看楼主
level 1
shy比邻 楼主
求批处理bat码,研究了一天没搞出来
2020年04月20日 14点04分 1
level 9
不清楚你的实际文件/情况,仅以问题中的样例/说明为据
复制粘贴到记事本,另存为xx.bat,编码选ANSI,跟要处理的文件放一起运行
<# :
cls
@璐村惂鐢ㄦ埛_000076K馃惥 off
rem 截取文本文件名称的后几位插入到文本文件的指定行
set #=Any question&set @=WX&set $=Q&set/az=0x53b7e0b4
title %#% +%$%%$%/%@璐村惂鐢ㄦ埛_053Q95e馃惥 %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
#>
$path=$args[0].trimend('\');
$newfolder=$path+'\#result';
if(-not (test-path -liter $newfolder)){[void](md $newfolder)};
$files=@(dir -liter $path|?{('.txt' -eq $_.Extension) -and ($_ -is [System.IO.FileInfo])});
if($files.length -ge 1){
$enc=[Text.Encoding]::Default;
write-host $files[0].Name;
$name=$files[0].BaseName -replace '^.*(.{5})$','$1';
$text=[IO.File]::ReadAllLines($files[0].FullName, $enc);
if($text.count -ge 2){
$text[2-1]='O'+$name+"`r`n"+$text[2-1];
};
[IO.File]::WriteAllLines($newfolder+'\'+$files[0].Name, $text, $enc);
}
2020年04月20日 15点04分 2
非常感谢,但是好像少了一个循环,不能批量处理,我对C#不太懂,能帮忙修改一下吗
2020年04月21日 04点04分
@shy比邻 按运行后窗口标题栏中的提示联系我
2020年04月21日 05点04分
1