带正则表达式的Windows批处理筛选器
我需要做一个蝙蝠脚本处理文件一个接一个,根据文件名中的数字。以下是我能得到的一个例子:带正则表达式的Windows批处理筛选器,windows,batch-file,scripting,Windows,Batch File,Scripting,我需要做一个蝙蝠脚本处理文件一个接一个,根据文件名中的数字。以下是我能得到的一个例子: CDEP_0003.pdf CIM_0001.pdf ESCALE_0002.pdf 是否可以使用正则表达式或类似的东西以有序的方式循环和处理这些文件中的每个文件,以排除数字并将其用作循环索引?(0001,0002,0003等)只需在*0000\.pdf$中循环到*9999\.pdf$上使用另一个答案只需在*0000\.pdf$中循环到*9999\.pdf$上使用另一个答案您可以 通过首先遍历文件来构建已用
是否可以使用正则表达式或类似的东西以有序的方式循环和处理这些文件中的每个文件,以排除数字并将其用作循环索引?(0001,0002,0003等)只需在
*0000\.pdf$
中循环到*9999\.pdf$
上使用另一个答案只需在*0000\.pdf$
中循环到*9999\.pdf$
上使用另一个答案您可以
- 通过首先遍历文件来构建已用数字的数组,或者
- 使用从10000到19999的计数循环(
)进行 前导零并取最后4位for/l
@Echo off
Pushd "X:\folder\to\start"
::clear array
for /f "delims==" %%A in ('Set No[ 2^>Nul') do Set "%%A="
:: fill array
for /f "tokens=2delims=_." %%A in (
'Dir /B "*_????.pdf" ^| findstr "^.*_[0-9][0-9][0-9][0-9]\.pdf$"'
) Do Set /A "No[%%A]=%%A"
:: process existing numbers
for /f "tokens=2 delims=[]" %%A in ('Set No[ 2^>Nul') do (
Rem dir "*_%%A.pdf" or whatever you want to do
)
你可以
- 通过首先遍历文件来构建已用数字的数组,或者
- 使用从10000到19999的计数循环(
)进行 前导零并取最后4位for/l
@Echo off
Pushd "X:\folder\to\start"
::clear array
for /f "delims==" %%A in ('Set No[ 2^>Nul') do Set "%%A="
:: fill array
for /f "tokens=2delims=_." %%A in (
'Dir /B "*_????.pdf" ^| findstr "^.*_[0-9][0-9][0-9][0-9]\.pdf$"'
) Do Set /A "No[%%A]=%%A"
:: process existing numbers
for /f "tokens=2 delims=[]" %%A in ('Set No[ 2^>Nul') do (
Rem dir "*_%%A.pdf" or whatever you want to do
)