Windows Batch File可将文件夹从文本文件复制到另一个目录
我正在尝试创建一个批处理文件,以读取文本文件并将包含这些文件的文件夹复制到另一个目录:Windows Batch File可将文件夹从文本文件复制到另一个目录,windows,batch-file,cmd,Windows,Batch File,Cmd,我正在尝试创建一个批处理文件,以读取文本文件并将包含这些文件的文件夹复制到另一个目录: set dest=f:\Test for /f %%i in (C:\dirs.txt) do copy "%%i" %dest% 当我运行此批处理文件时,只有文件会复制。我想用这些文件复制文件夹 IE文件夹\文件到目标\文件夹\文件。请查看xcopy xcopy /? 如果文本文件包含文件名,请尝试: xcopy "%%i" %dest%\ /S xcopy "%%i\*" %dest%\ /S 如
set dest=f:\Test
for /f %%i in (C:\dirs.txt) do copy "%%i" %dest%
当我运行此批处理文件时,只有文件会复制。我想用这些文件复制文件夹
IE文件夹\文件到目标\文件夹\文件。请查看
xcopy
xcopy /?
如果文本文件包含文件名,请尝试:
xcopy "%%i" %dest%\ /S
xcopy "%%i\*" %dest%\ /S
如果文本文件仅包含目录名,请尝试:
xcopy "%%i" %dest%\ /S
xcopy "%%i\*" %dest%\ /S
你拥有Vista还是更高版本?然后给robocopy一个镜头:
robocopy“源”“目标”/MIR
。其他一些选择:
Usage :: ROBOCOPY source destination [file [file]...] [options]
source :: Source Directory (drive:\path or \\server\share\path).
destination :: Destination Dir (drive:\path or \\server\share\path).
file :: File(s) to copy (names/wildcards: default is "*.*").
::
:: Copy options :
::
/S :: copy Subdirectories, but not empty ones.
/E :: copy subdirectories, including Empty ones.
/LEV:n :: only copy the top n LEVels of the source directory tree.
/Z :: copy files in restartable mode.
/B :: copy files in Backup mode.
/ZB :: use restartable mode; if access denied use Backup mode.
/COPY:copyflag[s] :: what to COPY (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
/SEC :: copy files with SECurity (equivalent to /COPY:DATS).
/COPYALL :: COPY ALL file info (equivalent to /COPY:DATSOU).
/NOCOPY :: COPY NO file info (useful with /PURGE).
/PURGE :: delete dest files/dirs that no longer exist in source.
/MIR :: MIRror a directory tree (equivalent to /E plus /PURGE).
/MOV :: MOVe files (delete from source after copying).
/MOVE :: MOVE files AND dirs (delete from source after copying).
/A+:[RASHNT] :: add the given Attributes to copied files.
/A-:[RASHNT] :: remove the given Attributes from copied files.
/CREATE :: CREATE directory tree and zero-length files only.
/FAT :: create destination files using 8.3 FAT file names only.
/FFT :: assume FAT File Times (2-second granularity).
/256 :: turn off very long path (> 256 characters) support.
/MON:n :: MONitor source; run again when more than n changes seen.
/MOT:m :: MOnitor source; run again in m minutes Time, if changed.
/RH:hhmm-hhmm :: Run Hours - times when new copies may be started.
/PF :: check run hours on a Per File (not per pass) basis.
/IPG:n :: Inter-Packet Gap (ms), to free bandwidth on slow lines.
用法::ROBOCOPY源目标[文件[文件]…][选项]
源::源目录(驱动器:\path或\\server\share\path)。
目的地::目的地目录(驱动器:\path或\\server\share\path)。
文件::要复制的文件(名称/通配符:默认值为“***”)。
::
::复制选项:
::
/复制子目录,但不要复制空的子目录。
/复制子目录,包括空目录。
/LEV:n::只复制源目录树的前n个级别。
/Z::以可重启模式复制文件。
/B::以备份模式复制文件。
/ZB::使用可重启模式;如果访问被拒绝,请使用备份模式。
/COPY:copyflag[s]::要复制的内容(默认为/COPY:DAT)。
(copyflags:D=数据,A=属性,T=时间戳)。
(S=安全性=NTFS ACLs,O=所有者信息,U=审核信息)。
/SEC::使用安全性复制文件(相当于/copy:DATS)。
/COPYALL::复制所有文件信息(相当于/COPY:DATSOU)。
/NOCOPY::不复制文件信息(与/PURGE一起使用很有用)。
/清除::删除源中不再存在的目标文件/目录。
/镜像目录树(相当于/E plus/PURGE)。
/MOV::移动文件(复制后从源中删除)。
/移动::移动文件和目录(复制后从源中删除)。
/A+:[RASHNT]::将给定属性添加到复制的文件中。
/A-:[RASHNT]::从复制的文件中删除给定的属性。
/创建::仅创建目录树和零长度文件。
/FAT::仅使用8.3 FAT文件名创建目标文件。
/FFT::假设FAT文件时间(2秒粒度)。
/256::关闭超长路径(>256个字符)支持。
/MON:n::监视源;当看到n个以上的更改时,请再次运行。
/MOT:m::监控源;如果更改,在m分钟内再次运行。
/RH:hhmm hhmm::运行小时数-可以启动新拷贝的时间。
/PF::基于每个文件(而不是每个过程)检查运行小时数。
/IPG:n::包间间隙(ms),用于在慢速线路上释放带宽。
Thera是更有趣的选择。在你弄乱文件之前,你可能应该先测试一下IE
@echo off
CD drive path of parent folder
mkdir A
CD ...\A
echo hello>1.txt
echo hello2>2.txt
mkdir A2
xcopy A "drive path"
start explorer.exe "path to A2"
这将建立一个基本的文件夹设置来测试它。
然后,如果可行,将其应用于文件路径。上述解决方案似乎将目录内容复制到目标的根目录。并且在包含空格的文件夹中存在问题。 尝试下面的几行来解决这个问题
set dest=e:\Test
for /f "delims=" %%i in (folders.txt) do xcopy "%%i\*" "%dest%\%%i\*" /E /F /Y
/E also copies empty subdirectories
/F lists the full filenames to copies (for debugging purposes)
/Y answers questions with yes.
不存在的目录将使用此命令创建,当目标中存在文件时,它将覆盖这些文件
delims=part确保从textfiles读取的目录可以包含空格yes,xcopy在将文件夹复制到文件夹时工作得特别好。将文件复制到文件夹有点棘手,但将文件夹复制到文件夹很容易。“xcopy.exe dirsrc dirdest/Q/F/D”基本上,如果文件夹a中有文件,我希望将文件夹a复制到其新文件夹destination@jeff然后使用
/S
而不是/E
。您是否已通读了xcopy/?
以了解如何使用它?我已阅读了指南,但仍在使用/s获取文件。我将/s放在%dest%/s之后。我也在使用windows 7。@Jeff我已经编辑了我的答案。如果您提供一个尾随的“\”,它会消除目标类型的歧义。不清楚源文件是否包含目录名或文件名。我提供了一个命令,用于.windows-Batch File将文件夹从一个文本文件复制到另一个目录-Stack overflow将基于文本文件自动复制文件您可以创建一个作业文件
并存储它。但这不是文本。如果您正在寻找纯文本解决方案,则需要批处理脚本、powershell、VB或类似工具。