因此,我希望将所有已转换文件夹下的文件从主Source文件夹移动到具有相同层次结构的另一个Output文件夹。
Source -done -converted -folder1 -done -converted -folder11 -done -converted -folder2 -done -converted至
Output (files from converted folder) -folder1 (files from converted folder) -folder11 (files from converted folder) -folder2 (files from converted folder)我是批处理脚本的新手,所以如果你能以某种方式帮助我,我将非常感激。 谢谢!!
So, I wish to move the files under all converted folders from the main Source folder to another Output folder having the same hierarchy.
Source -done -converted -folder1 -done -converted -folder11 -done -converted -folder2 -done -convertedTO
Output (files from converted folder) -folder1 (files from converted folder) -folder11 (files from converted folder) -folder2 (files from converted folder)I'm new to batch scripting so, I would really appreciate if you can help me in some way. Thanks!!
最满意答案
@ECHO OFF SETLOCAL SET source=c:\sourcedir SET destroot=c:\destdir SET cdtl=0 :loploop SET /a cdtl+=1 FOR /f "tokens=%cdtl%*delims=\" %%i IN ("%source%") DO IF NOT "%%j"=="" GOTO loploop FOR /f "delims=" %%i IN ( ' dir /b/s/ad "%source%\converted" ' ) DO CALL :movedest "%%~dpni%" ) GOTO :eof :movedest SET destdir=%~1 FOR /f "tokens=%cdtl%*delims=\" %%d IN (%1) DO SET destdir=%destroot%\%%e ECHO MD "%destdir%" 2>NUL ECHO MOVE /y "%~1\*.*" "%destdir%\" GOTO :eof倒数第二行中的ECHO简单地显示了所提出的操作。 在确认了您要执行的操作后,只需删除ECHO关键字即可执行移动操作。
请注意, MOVE命令中的/y开关将覆盖文件的任何现有目标版本。
@ECHO OFF SETLOCAL SET source=c:\sourcedir SET destroot=c:\destdir SET cdtl=0 :loploop SET /a cdtl+=1 FOR /f "tokens=%cdtl%*delims=\" %%i IN ("%source%") DO IF NOT "%%j"=="" GOTO loploop FOR /f "delims=" %%i IN ( ' dir /b/s/ad "%source%\converted" ' ) DO CALL :movedest "%%~dpni%" ) GOTO :eof :movedest SET destdir=%~1 FOR /f "tokens=%cdtl%*delims=\" %%d IN (%1) DO SET destdir=%destroot%\%%e ECHO MD "%destdir%" 2>NUL ECHO MOVE /y "%~1\*.*" "%destdir%\" GOTO :eofThe ECHOs in the penultimate two lines simply SHOW the operations that are proposed. After you've verified that's what you want to do, simply delete the ECHO keyword to perform the move.
Note that the /y switch in the MOVE command will overwrite any existing destination version of a file.
更多推荐
发布评论