如何在批处理文件中复制没有开始编号字符的文件
例如我的Dir列出了它:
12red.pcx
9red.pcx
96blue.pcx
alipro.pcx
然后我只需要批量复制alipro.pcx
将此批处理代码用于以数字char开头的复制文件:
@echo off
set Design_path=D:\
set USB_path=E:\usb\
set t12=12*.pcx
set t9=9*.pcx
set t6=6*.pcx
set tsize=*.pcx
set design12=Dis_12
set design9=Dis_9
set design6=Dis_6
set designsize=D_Size
rem // Create Dir if not exist
if not exist %Design_path%%design12% (mkdir %Design_path%%design12%)
if not exist %Design_path%%design9% (mkdir %Design_path%%design9%)
if not exist %Design_path%%design6% (mkdir %Design_path%%design6%)
if not exist %Design_path%%designsize% (mkdir %Design_path%%designsize%)
if exist %USB_path%%t12% copy %USB_path%%t12% %Design_path%%design12%
if exist %USB_path%%t9% copy %USB_path%%t9% %Design_path%%design9%
if exist %USB_path%%t6% copy %USB_path%%t6% %Design_path%%design6%
答案 0 :(得分:1)
此解决方案使用findstr的有限RegEx功能来仅选择行
开头的(^
锚点在开头),带有否定的字符类[^]
,但不是
零到九[^0-9]
for /f "delims=" %%a in (
'dir /B *.pcx^|findstr "^[^0-9]" '
) Do Echo copy %%a x:\whereever
如果要排除特殊号码,可以使用不同的RegEx 过滤与<{1}}选项匹配的 行 您可以使用SPACE分隔多个RegEx
/V
示例输出
for /f "delims=" %%a in (
'dir /B "*.pcx" ^|findstr /V "^6 ^9 ^12" '
) Do (
Echo %%a
Rem copy ...
)
答案 1 :(得分:0)
现在用于复制任何没有开始的文件,编号为9,6,12
例如我的列表:
3366.pcx
12gun.pcx
9ghost2.pcx
6bgre.pcx
avf.pcx
我只需要复制avf.pcx和3366.pcx。
这是我的代码
for /f "delims=" %%a in ('dir %USB_path% /b *.pcx^|findstr /r /c:"^[^9][^6][^12]" ') do (
echo %%a
copy "%USB_path%%%a" "%Design_path%%designsize%"
)