Board logo

标题: [文本处理] 如何批量处理一个文件夹指定行数的特殊字符的删减问题 [打印本页]

作者: jsqwert    时间: 2020-2-13 17:26     标题: 如何批量处理一个文件夹指定行数的特殊字符的删减问题

所有文件都会以这开头,第19行会不定时出现一个上箭头符号,怎么自动处理一个文件夹里的文件,另外文件最后如未是箭头就要删除箭头后面的空格
要更改成去掉箭头

也可以换成空格

要更改成去掉最后有箭头的空格

文件
作者: jsqwert    时间: 2020-2-13 21:00

补充下,前面段可用空格 替换箭头符号, 末尾处,如有箭头需删除箭头后的空格,如无箭头符号即 无需删除末尾的空格。
作者: Batcher    时间: 2020-2-14 08:55

回复 1# jsqwert


    请把1.txt和11.txt打包压缩传上来
作者: xczxczxcz    时间: 2020-2-14 12:52

你要把那个 箭头 发上来 让人家复制用啊。
作者: jsqwert    时间: 2020-2-17 15:17

回复 3# Batcher


    已经放 上两个文件
作者: zaqmlp    时间: 2020-2-20 14:43

修改原文件,注意备份
  1. <# :
  2. cls
  3. @echo off
  4. set info=互助互利,支付宝扫码头像,感谢打赏
  5. rem 有问题,可加QQ956535081及时沟通
  6. title %info%
  7. set "rootpath=%~dp0"
  8. if "%rootpath:~-1%" equ "\" (set "rootpath=%rootpath:~,-1%")
  9. cd /d "%rootpath%"
  10. powershell -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default))) -Args '%rootpath%'"
  11. echo;%info%
  12. pause
  13. exit
  14. #>
  15. $n=19;
  16. $files=@(dir -liter $args[0]|?{(@('.txt') -contains $_.Extension) -and ($_ -is [System.IO.FileInfo])});
  17. for($i=0;$i -lt $files.length;$i++){
  18.     write-host $files[$i].Name;
  19.     $text=[IO.File]::ReadAllText($files[$i].FullName, [Text.Encoding]::Default);
  20.     $text=$text -replace '(?<=\x0C)\s+$','';
  21.     $text=$text -split '\n';
  22.     if($text.length -ge $n){$text[$n-1]=$text[$n-1] -replace '\x0C','';};
  23.     $text=$text -join "`n";
  24.     [IO.File]::WriteAllText($files[$i].FullName, $text, [Text.Encoding]::Default);
  25. }
复制代码

作者: jsqwert    时间: 2020-2-21 10:36

回复 6# zaqmlp

如是要指定文件路径,应修改那里呢?
作者: zaqmlp    时间: 2020-2-21 13:54

回复 7# jsqwert

没赞助没动力




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2