Board logo

标题: [文本处理] bat有没有办法批量去除所有文本最后一行的空行? [打印本页]

作者: idc878787    时间: 2022-6-5 09:41     标题: bat有没有办法批量去除所有文本最后一行的空行?

本帖最后由 idc878787 于 2022-6-5 09:44 编辑

bat有没有办法批量去除所有文本最后一行的空行?


指定目录下的所有文件,子目录也要删除!!有没有办法?

文本有     񔥳񎒺                  &#这种符号
作者: flashercs    时间: 2022-6-5 10:06

本帖最后由 flashercs 于 2022-6-5 10:41 编辑
  1. @echo off
  2. cd /d "%~dp0"
  3. dir /a-d /b /s "D:\Test\*.txt"|powershell -c "$encoding=[system.text.encoding]::default;foreach($file in $input){[system.io.file]::writealltext($file,([system.io.file]::readalltext($file,$encoding) -replace '[\r\n]+$'),$encoding);}"
  4. pause
  5. exit /b
复制代码

作者: idc878787    时间: 2022-6-5 10:20

回复 2# flashercs


    谢谢
作者: wangrui    时间: 2022-12-17 09:03

回复 2# flashercs


    你真的太牛了。非常感谢。




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