|
|
发表于 2024-5-13 22:25:35
|
显示全部楼层
本帖最后由 aloha20200628 于 2024-5-13 22:32 编辑
回复 20# 娜美
‘一次性读写’ 改为 ‘逐行读写’ 方案》以便应付超大数据文件,不过还是采用了powershell中相当高效的[io.file]readLines/streamWriter
基于3楼代码改写如下,再试试吧...
- @echo off &setlocal &del /q "allinOne.txt" "bug.txt" 2>nul
- for /f "delims=" %%F in (b.txt) do if not exist "%%~F" (echo,"badFile -- %%F"&echo,%%F>>"bug.txt") else (
- for /f "tokens=1-2 delims=-" %%a in (' uchardet.exe "%%~F" ') do (
- if /i "%%a" neq "unknown" (echo, /// %%~F ///>>"allinOne.txt")
- if /i "%%a"=="utf" if "%%b"=="8" (
- powershell "$g=[text.encoding]::getEncoding('gb2312');$m=new-object io.streamWriter('allinOne.txt',$true,$g);foreach($l in [io.file]::readLines('%%~F',[text.encoding]::'utf8')){$m.writeLine($l)};$m.close()"
- ) else if /i "%%a"=="utf" if "%%b"=="16" (
- powershell "$g=[text.encoding]::getEncoding('gb2312');$m=new-object io.streamWriter('allinOne.txt',$true,$g);foreach($l in [io.file]::readLines('%%~F',[text.encoding]::'unicode')){$m.writeLine($l)};$m.close()"
- )
- if /i "%%a"=="ascii" (
- more "%%~F">>"allinOne.txt"
- ) else if /i "%%a"=="gb18030" (
- more "%%~F">>"allinOne.txt"
- ) else if /i "%%a"=="unknown" (
- echo,"unknown -- %%F"&echo,%%F>>"bug.txt"
- )
- )
- echo,>>"allinOne.txt"
- )
- endlocal&pause&exit/b
复制代码 |
|