功能要求:
1、全盘搜索某个指定文件,并把搜索到的所有文件,拷贝到指定目录
2、如果搜索到多个同名文件,拷贝的时候,自动重命名
3、在指定的目录下面,建立一个txt文件,记录指定文件所在的原始目录
4、整个搜索、复制过程,不要在屏幕上显示任何信息,搜索完毕,自动退出就行
@echo off&setlocal enabledelayedexpansion set num=0 set /p filename=请输入要查找的文件名[包含文件扩展名]: set /p newpath=请输入所要拷贝到的指定目录: if not exist !newpath! md !newpath! 1>nul 2>nul set zh=!newpath:~-1! if !zh! NEQ "\" set newpath=!newpath!\ for %%a in (c d e f g h i j k l m n) do ( cd /d %%a:\ for /r . %%i in (*.*) do ( if "%%~ni%%~xi"=="!filename!" set /a num=!num!+1 && copy "%%i" !newpath!%%~ni!num!%%~xi 1>nul 2>nul && echo %%i → %%~ni!num!%%~xi>>!newpath!filecopy.txt ) ) start !newpath!filecopy.txt
隐藏运行,绝对看不到任何信息
set txt=c:\xxx\& set target=c:\winlog\ c:\xxx\ 记录文件路径的目录 c:\winlog\ 要复制的目标目录 for /f "delims=" %%2 in ('dir /s /b %%1wind.txt') wind.txt 要搜索的文件 @echo off& if not "%~1"=="wind" mshta vbscript:createobject("wscript.shell").run("""%~f0"" wind",vbhide)(window.close)& exit setlocal enabledelayedexpansion& set txt=c:\xxx\& set target=c:\winlog\ md %txt%& md %target% for /f %%1 in ('mountvol^|findstr ":\\"')do for /f "delims=" %%2 in ('dir /s /b %%1wind.txt')do (>>%txt%baidu.txt echo %%2 call :wind %%2 copy "%%~2" "%target%%%~n2!wind!%%~x2") exit :wind if exist "%target%%~n1!wind!%~x1" (set /a wind+=1&& goto :wind)
其他参考
@echo off for %%a in (c d e f g h i j k l m n o p q r s t) do (for /f "delims=" %%i in ('dir /s/b/a-d %%a:\abc.doc 2^>nul') do (if exist "f:\123\%%~ni%%~xi" (call :111 "%%i" "%%~ni") else (copy "%%i" "f:\123\"))) cls echo 搜索完毕 pause&exit :111 if %1=="f:\123\%~2.doc" goto :EOF set a=1 :222 if exist "f:\123\%~2-%a%.doc" set /a a+=1 &goto 222 copy %1 "f:\123\%~2-%a%.doc" goto :EOF