我想做的是跟随。 我想创建一些bat文件,它将递归搜索从当前目录开始的文件,并替换为我提供的文件。 对于前者 如果我想搜索并替换test1.txt,我打开这个迷你应用程序并编写text1.txt,并放置我想要替换的文件。
迪尔 app.bat test1.txt // app将递归搜索文件夹1和文件夹2,并将用test1.txt替换所有找到的结果 文件夹1 文件夹2我想知道,如果因为这个原因准备好去app或bat文件?
What I want to do is following. I want to create some bat file, that will recursively search for files starting from current directory and replace with the file that I provided. For ex. if I want to search and replace test1.txt, I'm opening this mini app and writing text1.txt, and placing the file that I want to be replaced with.
Dir app.bat test1.txt // app will recursively search inside folder 1 and folder 2 and will replace all found results with test1.txt folder 1 folder 2I wonder, if there is ready to go app or bat file for this reason?
最满意答案
下面的批处理文件从当前目录开始,递归搜索第一个参数中给出的文件,并在其上复制(使用相同名称)第二个参数中给出的文件:
@echo off set targetName=%~NX1 set replacementFile=%~F2 call :processFolder goto :EOF :processFolder rem For each folder in this level for /D %%a in (*) do ( rem Enter into it, process it and go back to original cd %%a if exist "%targetName%" ( copy "%replacementFile%" "%targetName%" /Y ) call :processFolder cd .. ) exit /B例如:
app test1.txt c:\data\replacementfile.txtThe Batch file below start from current directory, recursively search the file given in the first parameter and copy over it (with same name) the file given in second parameter:
@echo off set targetName=%~NX1 set replacementFile=%~F2 call :processFolder goto :EOF :processFolder rem For each folder in this level for /D %%a in (*) do ( rem Enter into it, process it and go back to original cd %%a if exist "%targetName%" ( copy "%replacementFile%" "%targetName%" /Y ) call :processFolder cd .. ) exit /BFor example:
app test1.txt c:\data\replacementfile.txt更多推荐
发布评论