我自己写了一个,又臭又长:- @echo off & SetLocal EnableDelayedExpansion
- set "str00=V:\*.txt"
- set "str00=V:\新 建\新建 文件夹 (0)\*.txt"
-
- :: 替换空格\符号为标签
- set "str01=%str00: =#CHR32#%"
- set "str01=%str01:\=#CHR92#%"
-
- :: 计数
- set/a n=0
- Call :_count_args %str01:#CHR92#= %
- set/a nCount=%n%
-
- :: 合并字符串
- set str=
- set/a n=1
- Call :_join_args %str01:#CHR92#= %
-
- :: 移除标签后得到1部分
- set "str02=%str:#CHR92#=\%"
- set "str02=%str02:#CHR32#= %"
- :: 替换字符后得到2部分
- set "str03=!str00:%str02%\=!"
-
- echo nCount --%nCount%--
- echo str00 --%str00%--
- echo str01 --%str01%--
- echo str02 --%str02%--
- echo str03 --%str03%--
- pause
-
- :: 计数
- :_count_args
- set/a n+=1
- SHIFT
- echo,%~1
- if "%~1" neq "" goto :_count_args
- goto :eof
-
- :: 合并字符串
- :_join_args
- if %n% GEQ %nCount% goto :eof
- set/a n+=1
- if defined str (set "str=%str%#CHR92#%~1") else (set "str=%~1")
- SHIFT
- goto :_join_args
- goto :eof
复制代码
|