不清楚你的实际文件/情况,仅以问题中的样例/说明为据
复制粘贴到记事本,另存为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);
}
复制粘贴到记事本,另存为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);
}