使用批量脚本将文件从一个文件夹移动到具有相同层次结构和文件夹名称的另一个文件夹?(Move files from one folder to another folder having the sam

编程入门 行业动态 更新时间:2024-10-28 16:21:43
使用批量脚本将文件从一个文件夹移动到具有相同层次结构和文件夹名称的另一个文件夹?(Move files from one folder to another folder having the same hierarchy and folder name using batch scripting?)

因此,我希望将所有已转换文件夹下的文件从主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 -converted

TO

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 :eof

The 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.

更多推荐

本文发布于:2023-08-07 06:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462557.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件夹   批量   脚本   层次   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!