我正在寻找批处理来查找并将文本文件中列出的所有文件夹复制到指定的位置。
例如a has:
Textfile.txt机智内容:
包含子文件夹的头文件夹。
我正在寻找的文件夹(来自Textfile.txt的文件夹)可以放在每个子文件夹中。 如果我想查找并从Textfile.txt复制文件夹到指定的位置。我需要从头文件夹中搜索所有子文件夹
示例文件夹树
请帮我批量施工。感谢。
其他信息:
- Home folder (head folder) - John (folder) - 01 (folder) (can be blank, without any folders and files) - 11st (folder) (can be blank, without any folders and files) - file1.txt (files) - file2.xls - 12st - 13st - 02 - 03 - 04 - Thomas - 05 - 11st - 12st - 13st - 06 - Ewa - Martin - 07 - 11st - 12st - 15st - George - 08
我需要从Textfile.txt中找到并复制整个文件夹01,02,03,04等,即使它们是空白的。
答案 0 :(得分:0)
以下内容应在批处理文件中起作用:
FOR /F %%F IN (Textfile.txt) DO xcopy /I /E "C:\Source\%%F" "D:\Dest\%%F"
您还可以应用更多开关:
/C Continues copying even if errors occur.
/H Copies hidden and system files also.
/R Overwrites read-only files.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
<强>更新强>
在特定情况下,如果您有分散在子文件夹中的文件夹列表,则此脚本应该可以正常运行:
@echo off
set SRC_FOLDER="C:\Source"
set DST_FOLDER="C:\Destination"
REM this makes sure that if the first folder in list is empty - it is copied
IF NOT EXIST %DST_FOLDER% MKDIR %DST_FOLDER%
REM loop through the items in list; use one per line
REM for group match use <NAME>*
FOR /f %%F IN (%~dp0\Textfile.txt) DO (
REM loop through all folders
FOR /f "delims=" %%D IN ('DIR %SRC_FOLDER% /A:D /B') DO (
REM loop through FOLDER/NAME* sub-folders
FOR /f "delims=" %%G IN ('DIR %SRC_FOLDER%\"%%D\%%F" /A:D /B') DO (
IF EXIST %SRC_FOLDER%\"%%D\%%G" XCOPY /I /E %SRC_FOLDER%\"%%D\%%G" %DST_FOLDER%\"%%~nG"
)
REM loop through all FOLDER subfolders to catch NAME subfolders
FOR /f "delims=" %%G IN ('DIR %SRC_FOLDER%\"%%D" /A:D /B') DO (
IF "%%G" == "%%F" XCOPY /I /E %SRC_FOLDER%\"%%D\%%G" %DST_FOLDER%\"%%~nG"
)
)
)
enter code here