批处理查找复制文件

经常在公司听到有同事黑这脸说累死了,在电脑前坐了一整天了,事情还没有做完。要加班才能完成。电脑是个个工具,工具的使用本来提高了效率,但是很多人没有将这个工具用好,所以效率还是不够高。学到手一些CMD命令有些时候真的是你一分钟做完的事,别人可能要几天才完成,可能出错。下面介绍这个查找文件并复制或者做其他,举一反三,可以实现很多…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
echo on
echo 测试
del 123.txt
for %%a in (c d e f g ) do dir %%a:\*.pdf /s/b >>123.txt
::查找电脑硬盘中的C\D\E\F\G盘中的pdf文档,并将所有文档路径写入到123.txt
::for %%a in ()do 语句 括号内的内容=%%a,括号内的内容用空格隔开
for %%a in (c d e f g) do dir %%a:\*.dwg /s/b >>123.txt
md h:\123
::在h盘下创建目录,名称123
for /f "delims==" %%a in (123.txt) do xcopy %%a /s/y h:\123\
::将前两步查找出来的符合搜索条件的文件复制到h盘下的123目录。
::for /f "delims==" %%a in ()do 语句 括号内的为文件
del 123.txt
echo 测试完成!

简化以上:

1
2
3
4
5
6
7
8
9
10
echo on
echo 测试
del 123.txt
for %%a in (c d e f g ) do dir %%a:\ /s/b >>123.txt
findstr /i /l ".dxf .dwg" 123.txt >234.txt
@ping -n 3 127.1 > nul
if not exist h:\123 md h:\123
for /f "delims==" %%a in (234.txt) do xcopy %%a /s/y h:\123\
del 123.txt 234.txt
echo 测试完成!

c echo on echo 测试 del 123.txt for %%a in (c d e f g ) do dir %%a:\ /s/b >>123.txt findstr /i /l ".dxf .dwg .doc .xls .ppt" 123.txt >234.txt @ping -n 3 127.1 > nul if not exist h:\123 md h:\123 for /f "delims==" %%b in (234.txt) do del %%b /f/q/s del 123.txt 234.txt echo 测试完成! [[]]