本帖最后由 yhcfsr 于 2018-3-16 06:36 编辑
回复 3# f0229f0229 - @echo off
- for /f "delims=" %%a in ('dir /a-d/s/b *.txt') do (
- (for /f "tokens=* delims= " %%i in ('type "%%a"') do echo %%i)>temp.txt
- move /y "temp.txt" "%%a"
- )
复制代码 这个只是去掉第一列前的空格而已。下面的方法将空格转换为制表符,不用再去EXCEL中分列转换,但限制性很强,适合数字之间最多只有两个空格的情况,否则就要修改代码。
总之用BAT限制多,用powershell的话就能写出通用性很好的脚本。- @echo off
- for /f "delims=" %%a in ('dir /a-d/s/b *.txt') do (
- (for /f "tokens=* delims= " %%i in ('type "%%a"') do echo %%i)>temp.txt
- (for /f "delims=" %%w in ('type temp.txt') do (
- set "str=%%w"
- setlocal enabledelayedexpansion
- set "str=!str: = !"&&set "str=!str: = !"
- echo !str!
- endlocal
- ))>"%%a"
- del /f /q temp.txt
- )
复制代码 POWERSHELL(推荐)- $ScDir="D:\test folder"; #源目录
- Get-ChildItem -Path $ScDir -Recurse|ForEach-Object{
- $content=Get-Content -Path $_.FullName;$str=$null;
- foreach($line in $content) {
- $str+=($line.Trim()|ForEach-Object{$_ -Replace '\s{1,}',"`t"})+"`r`n";
- }
- Out-File -FilePath $_.FullName -InputObject $str;
- }
复制代码
|