批处理脚本:find并复制未知目录中的文件?

我需要为我的同伴制作一个batch file(实际上,我需要制作一个程序序列,但为了简单,我使用batch file)。

批处理的工作是将计算机中的特定文件复制到batch file夹。 但问题是我不知道所有我的同伴的文件的path。

这是我需要的东西:

  1. 帮助我的同class同学select他们的path。 (也许只是在他们的电脑中自动find该文件)。

  2. 复制该文件并将其粘贴到batch file的文件夹(其中包括我的其他程序)。

  3. 毕竟我的其他程序完成他们的工作,复制并replace该文件到其原始文件夹。

你有任何脚本可能有帮助吗?

Solutions Collecting From Web of "批处理脚本:find并复制未知目录中的文件?"

您可以从这个批处理代码开始:

@echo off Title Search for a file by name (Wildcard accepted) by Hackoo 2014 mode con cols=90 lines=5 & color 9B echo( Set /p "FileName=Please Enter the name of the file to find (Wildcard accepted) : " echo( Set Tmp=Tmp.txt Set SearchResult=SearchResult.txt Call :BrowseFolder "Select the Source folder" "C:\Program" Set LocationFolder=%MyFolder% echo You chose to looking into "%LocationFolder%" for this file "%FileName%" echo( & cls & Color 0A echo( & echo Please Wait for moment .... Searching for "%FileName%" on "%LocationFolder%" Where /r "%LocationFolder%" "%FileName%" > %Tmp% Cmd /U /C Type %Tmp% > %SearchResult% Del %Tmp% Start %SearchResult% ::****************************************************************************** :BrowseFolder set MyFolder= set vbs="%temp%\_.vbs" set cmd="%temp%\_.cmd" for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= >%vbs% echo set WshShell=WScript.CreateObject("WScript.Shell") >>%vbs% echo set shell=WScript.CreateObject("Shell.Application") >>%vbs% echo set f=shell.BrowseForFolder(0,%1,0,%2) >>%vbs% echo if typename(f)="Nothing" Then >>%vbs% echo wscript.echo "set MyFolder=Dialog Cancelled" >>%vbs% echo WScript.Quit(1) >>%vbs% echo end if >>%vbs% echo set fs=f.Items():set fi=fs.Item() >>%vbs% echo p=fi.Path:wscript.echo "set MyFolder=" ^& p cscript //nologo %vbs% > %cmd% for /f "delims=" %%a in (%cmd%) do %%a for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= ::****************************************************************************** 

编辑:2015年6月28日在07:00

 @echo off Title Search for a file by name and copy it (Wildcard accepted) by Hackoo 2015 mode con cols=90 lines=5 & color 9B Set /p "FileName=Please Enter the name of the file to find (Wildcard accepted) : " Set SearchResult=SearchResult.txt Call :BrowseFolder "Select the Source folder" "C:\Program" Set LocationFolder=%MyFolder% echo You chose to looking into "%LocationFolder%" for this file "%FileName%" echo( & cls & Color 0A echo( & echo Please Wait for moment .... Searching for "%FileName%" on "%LocationFolder%" where /r "%LocationFolder%" "%FileName%" > %SearchResult% Goto:CopyMyFile ::****************************************************************************** :BrowseFolder set MyFolder= set vbs="%temp%\_.vbs" set cmd="%temp%\_.cmd" for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= >%vbs% echo set WshShell=WScript.CreateObject("WScript.Shell") >>%vbs% echo set shell=WScript.CreateObject("Shell.Application") >>%vbs% echo set f=shell.BrowseForFolder(0,%1,0,%2) >>%vbs% echo if typename(f)="Nothing" Then >>%vbs% echo wscript.echo "set MyFolder=Dialog Cancelled" >>%vbs% echo WScript.Quit(1) >>%vbs% echo end if >>%vbs% echo set fs=f.Items():set fi=fs.Item() >>%vbs% echo p=fi.Path:wscript.echo "set MyFolder=" ^& p cscript //nologo %vbs% > %cmd% for /f "delims=" %%a in (%cmd%) do %%a for %%f in (%vbs% %cmd%) do if exist %%f del %%f for %%g in ("vbs cmd") do if defined %%g set %%g= ::****************************************************************************** :CopyMyFile Cls for /f "delims=*" %%a in (%SearchResult%) do (echo Copy "%%a" "%~dp0" & Copy "%%a" "%~dp0") Pause 

dir c:\nameoffiletosearch /s /b > %temp%\results.txt会在驱动器c中创建一个包含文件全部路径的列表。

你甚至可以把它包装在一个搜索多个驱动器的循环中。

然后从results.txt获取路径,并将其与您的复制命令一起使用。