以前用Fsutil 也就是用来列出盘符,生成指定大小文件,等等……
而昨日,在batman发的练习中要求文本处理,把一行字符串大概每60个字节分一次行。
当时恶搞了一下,用mode con cols=61 lines=25 限制输出。
当时联想到了用fsutil 可以实现字节操作,探索了一天,感觉还可以。
已知特性
1。"%!a!%"这样的字符,可以通过。
2。可按字节做切割操作。缺点也在此,当中文与单字节字符混合时,切割很可能会把中文的“码”分割
所以一般适合于 纯单字节或者纯双字节的文本操作。
要实现通用可能又需要不少判断。
3。感觉效率不是好。
也因此,我决定对于那个练习的解答,另外发帖,是为了突出fsutil的字节操作特性,以及希望另外讨论。
下面我用批处理打包的代码,自主建立适当环境,代码仅为测试阶段,诸多缺点,欢迎批评指出。
- @set file="cuter.bat" "text.txt"
- @echo off
- ::code by 523066680@cn-dos.net
- if not exist Testx md Testx
- for %%a in (%file%) do (call :setup %%~a)
- exit
- :setup
- set "act="
- for /f "delims= eol=#" %%a in (%~nx0) do (
- if "%%a"=="::%* end" (goto :eof)
- if defined act echo,%%a>>"Testx\%*"
- if "%%a"=="::%*" errcommand>"Testx\%*" 2>nul&set act=act
- )
- ::cuter.bat
- @echo off
- err>result.x 2>nul
- for /f "delims= eol=#" %%a in (text.txt) do (
- for %%b in (0 1 2 3 4) do (
- set /a seta=%%b*61,setb=seta+61
- echo, %%a>temp.x
- call :func %%seta%% %%setb%%
- )
- )
- start result.x
- pause
- exit
- :func
- fsutil file setzerodata offset=0 length=%1 temp.x >nul
- fsutil file setzerodata offset=%2 length=10000 temp.x >nul
- for /f "delims= eol=#" %%c in ('more temp.x') do (echo,%%c>>result.x)
- goto :eof
- ::cuter.bat end
- ::text.txt
- "Finally, a step-by-step VBScripting book to make you look like a programmer without the time and sweat! Don't waste your time searching the Internet for examples-this book does it for you!"
- -Greg A. Marino, Senior Systems Engineer/Consultant, Westtown Consulting Group, Inc.
- Visual Basic Scripting (VBScript) and Windows Management Instrumentation (WMI) are vital tools for systems administrators grappling with the increasing complexity of Windows technologies. However, busy admins have been without a straightforward guide to scripting...until now.%!test!%
- ::text.txt end
复制代码
生成的测试文件夹为Testx |