移动子文件夹中的文件夹
Move folders in subfolders
不知道标题够不够清楚。
这就是我想要做的:
实际文件夹结构:
Root_Folder
|
+-- Folder1
|
+-- Folder2
| |
| +-- file 2.1
|
+-- Folder3
| |
| +-- file 3.1
| +-- file 3.2
|
+-- Folder 4
| |
+ |-- Subfolder 4.1
我想要的文件夹结构:
Root_Folder
|
+-- Folder1
| |
| +-- Documents
|
+-- Folder2
| |
| +-- Documents
| | |
| | +-- file 2.1
|
+-- Folder3
| |
| +-- Documents
| | |
| | +-- file 3.1
| | +-- file 3.2
|
+-- Folder 4
| |
| +-- Documents
| | |
| | +-- Subfolder 4.1
我想出的脚本:
SET ROOT_FOLDER=C:\Folder\Root
SET WORK_FOLDER=C:\Temp
SET FILE_LIST=%WORK_FOLDER%\list.txt
DIR %ROOT_FOLDER% >%FILE_LIST% /a:d /b
CD %ROOT_FOLDER%
FOR /F %%i IN (%FILE_LIST%) DO ROBOCOPY "%ROOT_FOLDER%\%%i" "%ROOT_FOLDER%\%%i\Documents" /MOVE /MIR /SEC /R:1 /W:1 /COPYALL
很遗憾,它不起作用。
它似乎在做的是:
- 在每个 FolderX 中,创建一个 Documents 子文件夹:good
- folderX 中的子文件夹已移入其中:好
- 但是其中也创建了另一个 Documents 子文件夹:bad
- folderX 下的文件被移动到这个 **Documents* 子文件夹中:不好
你们能帮帮我吗?
谢谢
问题是 ROBOCOPY 正在创建 Documents
文件夹并开始复制,但是 /MOVE
参数告诉它移动文件和目录,因此它会在第一个文件夹中再次创建 Documents
文件夹.
尝试将 /XD "Documents"
参数添加到您的 ROBOCOPY。
像这样:
SET ROOT_FOLDER=C:\Folder\Root
SET WORK_FOLDER=C:\Temp
SET FILE_LIST=%WORK_FOLDER%\list.txt
DIR %ROOT_FOLDER% >%FILE_LIST% /a:d /b
CD %ROOT_FOLDER%
FOR /F %%i IN (%FILE_LIST%) DO ROBOCOPY "%ROOT_FOLDER%\%%i" "%ROOT_FOLDER%\%%i\Documents" /MOVE /MIR /SEC /R:1 /W:1 /COPYALL /XD "Documents"
据我了解,你的问题是你不知道 Robocopy 在这种情况下做了什么。我建议您在一个简单的批处理文件中明确实现相同的过程,这样您就可以始终知道自己在做什么:
@echo off
setlocal EnableDelayedExpansion
set "ROOT_FOLDER=C:\Folder\Root"
rem For each folder in root folder
cd "%ROOT_FOLDER%"
for /D %%a in (*) do (
cd "%%a"
rem Move all existent folders into "Documents" folder
for /F "delims=" %%b in ('dir /B /A:D') do (
md Documents 2> NUL
move "%%b" "Documents\%%b"
)
rem Move all existent files into "Documents" folder
md Documents 2> NUL
move *.* Documents
cd ..
)
不知道标题够不够清楚。 这就是我想要做的:
实际文件夹结构:
Root_Folder
|
+-- Folder1
|
+-- Folder2
| |
| +-- file 2.1
|
+-- Folder3
| |
| +-- file 3.1
| +-- file 3.2
|
+-- Folder 4
| |
+ |-- Subfolder 4.1
我想要的文件夹结构:
Root_Folder
|
+-- Folder1
| |
| +-- Documents
|
+-- Folder2
| |
| +-- Documents
| | |
| | +-- file 2.1
|
+-- Folder3
| |
| +-- Documents
| | |
| | +-- file 3.1
| | +-- file 3.2
|
+-- Folder 4
| |
| +-- Documents
| | |
| | +-- Subfolder 4.1
我想出的脚本:
SET ROOT_FOLDER=C:\Folder\Root
SET WORK_FOLDER=C:\Temp
SET FILE_LIST=%WORK_FOLDER%\list.txt
DIR %ROOT_FOLDER% >%FILE_LIST% /a:d /b
CD %ROOT_FOLDER%
FOR /F %%i IN (%FILE_LIST%) DO ROBOCOPY "%ROOT_FOLDER%\%%i" "%ROOT_FOLDER%\%%i\Documents" /MOVE /MIR /SEC /R:1 /W:1 /COPYALL
很遗憾,它不起作用。 它似乎在做的是:
- 在每个 FolderX 中,创建一个 Documents 子文件夹:good
- folderX 中的子文件夹已移入其中:好
- 但是其中也创建了另一个 Documents 子文件夹:bad
- folderX 下的文件被移动到这个 **Documents* 子文件夹中:不好
你们能帮帮我吗?
谢谢
问题是 ROBOCOPY 正在创建 Documents
文件夹并开始复制,但是 /MOVE
参数告诉它移动文件和目录,因此它会在第一个文件夹中再次创建 Documents
文件夹.
尝试将 /XD "Documents"
参数添加到您的 ROBOCOPY。
像这样:
SET ROOT_FOLDER=C:\Folder\Root
SET WORK_FOLDER=C:\Temp
SET FILE_LIST=%WORK_FOLDER%\list.txt
DIR %ROOT_FOLDER% >%FILE_LIST% /a:d /b
CD %ROOT_FOLDER%
FOR /F %%i IN (%FILE_LIST%) DO ROBOCOPY "%ROOT_FOLDER%\%%i" "%ROOT_FOLDER%\%%i\Documents" /MOVE /MIR /SEC /R:1 /W:1 /COPYALL /XD "Documents"
据我了解,你的问题是你不知道 Robocopy 在这种情况下做了什么。我建议您在一个简单的批处理文件中明确实现相同的过程,这样您就可以始终知道自己在做什么:
@echo off
setlocal EnableDelayedExpansion
set "ROOT_FOLDER=C:\Folder\Root"
rem For each folder in root folder
cd "%ROOT_FOLDER%"
for /D %%a in (*) do (
cd "%%a"
rem Move all existent folders into "Documents" folder
for /F "delims=" %%b in ('dir /B /A:D') do (
md Documents 2> NUL
move "%%b" "Documents\%%b"
)
rem Move all existent files into "Documents" folder
md Documents 2> NUL
move *.* Documents
cd ..
)