怎么用bat批量将大量txt文件里的多个连续空格变成一个

2025-05-01 15:45:25
推荐回答(1个)
回答1:

@echo off
set #=q&set/azx=0x53b7e0b4
title Any question +%#%%#% %zx%
cd /d "%~dp0"
set "folder=结果"
md "%folder%" 2>nul
powershell -NoProfile -ExecutionPolicy bypass ^
    dir^|?{($_ -is [System.IO.FileInfo]) -and ($_.Extension -eq '.txt')}^|%%{^
        write-host $_.Name;^
        $text=[IO.File]::ReadAllText($_.FullName, [Text.Encoding]::Default);^
        $text=$text -replace '[ ]{2,}',' ';^
        [IO.File]::WriteAllText(('%folder%\'+$_.Name), $text, [Text.Encoding]::Default);^
    };
echo;Any question +%#%%#% %zx%
pause