我的文件夹结构如下:
-MainDir -f0 -f0 -f0 -a.txt -b.txt -c.txt -f1 -f1 -f1 -aa.txt -bb.txt -cc.txt如果您在上方看到我的文件,则它们位于层次结构的第3个文件夹中.现在,我的要求是仅能够将主文件夹及其文件复制到另一个位置.例如:以上结构的输出应如下所示:
If you see above my files are in 3rd folder in terms of hierarchy. Now my requirement is to be able to copy only the main folder and it's files to another location. For example: output for above structure should be as following:
-MainDir -f0 -a.txt -b.txt -c.txt -f1 -aa.txt -bb.txt -cc.txt但是当我尝试使用XCOPY时,所有文件夹都照原样复制.因此,我试图找出一种实现目标文件夹结构的方法,如上所示
but when I try using XCOPY, all the folders get copied as it is. So I am trying to figure out a way to achieve my target folder structure as shown above
推荐答案以下内容将循环查找main下的目录,查找所有文件,并将它们全部放入目标位置中最顶层的子目录中:
The following will loop the directories under main, find all files, and put them all in the top most sub directory in destination as you're looking for:
CMD脚本:
@(SETLOCAL ECHO OFF SET "_MainDir=C:\Main\Dir" SET "_DestDir=%Temp%\Destination\Main\Dir" ) FOR /D %%A in ( %_MainDir%\* ) DO ( IF NOT EXIST "%_DestDir%\%%~nxA" MD "%_DestDir%\%%~nxA" FOR /F %%a IN (' DIR /A-D /S /B "%%~fA\*" ') DO ( ECHO Copying: "%%~fa" ECHO To: "%_DestDir%\%%~nxA\%%~nxa" COPY /B /V /Y "%%~fa" "%_DestDir%\%%~nxA\%%~nxa" ) )更多推荐
如何仅使用cmd从子文件夹复制文件?
发布评论