Windows 它可以创建一个自定义批,用于将自定义扩展文件移动到新创建的文件夹中
在一个cmd???A中,所有这些只是一系列由新行分隔的命令:Windows 它可以创建一个自定义批,用于将自定义扩展文件移动到新创建的文件夹中,windows,batch-file,for-loop,findstr,robocopy,Windows,Batch File,For Loop,Findstr,Robocopy,在一个cmd???A中,所有这些只是一系列由新行分隔的命令: Move*.docx”%UserProfile%\Documents\NewDirectory 移动*.pdf“%UserProfile%\Documents\NewDirectory” 移动*.txt“%UserProfile%\Documents\NewDirectory” 移动*.xls“%UserProfile%\Documents\NewDirectory” 或串联器(与号和): Move*.docx”%UserProfi
Move*.docx”%UserProfile%\Documents\NewDirectory
移动*.pdf“%UserProfile%\Documents\NewDirectory”
移动*.txt“%UserProfile%\Documents\NewDirectory”
移动*.xls“%UserProfile%\Documents\NewDirectory”
或串联器(与号和):
Move*.docx”%UserProfile%\Documents\NewDirectory“&Move*.pdf”%UserProfile%\Documents\NewDirectory“&Move*.txt”%UserProfile%\Documents\NewDirectory“&Move*.xls”%UserProfile%\Documents\NewDirectory”
您还可以使用:
对于%%I In(docx pdf txt xls)执行移动“*.%%I”“%UserProfile%\Documents\NewDirectory”
上述所有方法的最大问题是,对于大多数命令,Windows将*.ext
视为以.ext
开头的任何扩展,这意味着,例如.xls
实际上也包括.xlsb
、.xlsm
和.xlsx
扩展
有几种方法可以防止此类问题,第一种是使用if
命令:
For%%I In(docx pdf txt xls)Do If/I Not“%%~xI”=”.xlsb“If/I Not”%%~xI”=”.xlsm“If/I Not”%%~xI”=”.xlsx“Move”*。%%I”“%UserProfile%\Documents\NewDirectory”
通过以下方式过滤结果:
For/F“EOL=?Delims=“%%I In('Dir/B/A:-D*.docx*.pdf*.txt*.xls 2^>NUL^”“%\uu AppDir\uuu%findstr.exe”/V/I“\.xlsb$\.xlsm$\.xlsx$”)移动“*.%%I”“%UserProfile%\Documents\NewDirectory”
上述所有方法的问题在于,它们希望目标目录首先实际存在,这意味着您需要使用MD
命令,即MD”%UserProfile%\Documents\NewDirectory“2>NUL
使用(尽管其名称也可以移动
文件),如果目标目录不存在,也会自动创建目标目录,您可以使用其
/XF选项排除那些可能的恶意文件扩展名:
“%\uuuuu AppDir\uuuuu%robocy.exe”。“%UserProfile%\Documents”*.docx*.pdf*.txt*.xls/Mov/XF*.xlsb*.xlsm*.xlsx”
我已经使用“
将当前目录表示为源目录(如果需要,当然可以使用特定的完整路径或相对路径)
move *.docx %userprofile%\Documents\ move *.pdf %userprofile%\Documents\ move *.txt %userprofile%\Documents\ move *.xls %userprofile%\Documents\