Batch file 复制文件在批处理中不以数字字符开头

Batch file 复制文件在批处理中不以数字字符开头,batch-file,Batch File,如何在批处理文件中复制没有开始编号字符的文件 例如,my Dir列出其: 12red.pcx 9red.pcx 96blue.pcx alipro.pcx 3366.pcx 12gun.pcx 9ghost2.pcx 6bgre.pcx avf.pcx 那么我只需要批量复制alipro.pcx 对于以数字字符开头的复制文件,请使用此批处理代码: @echo off set Design_path=D:\ set USB_path=E:\usb\ set t12=12*.pcx set t9=

如何在批处理文件中复制没有开始编号字符的文件

例如,my Dir列出其:

12red.pcx
9red.pcx
96blue.pcx
alipro.pcx
3366.pcx
12gun.pcx
9ghost2.pcx
6bgre.pcx
avf.pcx
那么我只需要批量复制alipro.pcx

对于以数字字符开头的复制文件,请使用此批处理代码:

@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%

现在复制任何文件,但不从数字9、6、12开始

例如,我的列表:

12red.pcx
9red.pcx
96blue.pcx
alipro.pcx
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%"
  )

此解决方案使用findstr有限的正则表达式功能仅选择行 开头^以否定字符类[^]开头锚定,该类不是 零到九[^0-9]

如果要排除特殊数字,可以使用不同的正则表达式 筛选与选项不匹配的行/V 可以使用空格分隔多个正则表达式

for /f "delims=" %%a in (
  'dir /B "*.pcx" ^|findstr /V "^6 ^9 ^12" '
) Do (
  Echo %%a
  Rem copy ...
)
样本输出

> Dir /B
11foo.pcx
12red.pcx
13bar.pcx
3366.pcx
96blue.pcx
9red.pcx
alipro.pcx

> SO_44875749.cmd
11foo.pcx
13bar.pcx
3366.pcx
alipro.pcx

您的代码与您的需求有何关联?至于请求。我会在“dir/B*.pcx^ findstr^[^0-9]”中使用for/f delims=%%a进行回显复制%%a x:\whereever刚刚看到%%a的大小写有错误的不同-将它们更改为大小写相等。@LotPings我需要复制除以9、6和12开头的文件以外的任何文件。此代码不起作用:对于/f delims=%%a in'dir%USB_path%/b*.pcx^ findstr/r/c:^[^6][^6][^12]'是否echo%%a copy%USB_path%%%a%Design_path%%designsize%请帮助meSo不同于您的第一个要求您想排除指定的数字不是全部?顺便说一句,如果你有其他人可能感兴趣的解决方案,最好编辑你的问题并只回答你自己的问题。请参阅我自己的答案