如何复制子文件夹中的所有文件

如何复制子文件夹中的所有文件

我使用的是 Windows 7,我想将文件夹及其所有子文件夹中的所有 PDF 文件复制到新位置。执行此操作的命令是什么?

答案1

使用xcopy命令。您可以进入命令提示符并键入xcopy /?以获取使用它的帮助。

对于您的特定问题,完整命令将是:

xcopy c:\sourcefolder\*.pdf c:\destinationfolder\ /e

答案2

如果您希望将所有 PDF 放入一个文件夹中:

copy <source path>\*.pdf <destination path> /s

如果要保留原始文件夹结构:

xcopy <source path>\*.pdf <destination path> /s

答案3

我强烈建议您使用 RoboCopy,因为它有丰富的选项(远远超出我提供的列表)。但是,由于您只想复制 PDF 文件,请使用此语法

Robocopy C:\Users C:\UserBackup *.pdf

Robocopy Syntax
ROBOCOPY source destination [file [file]…] [options]
where source is Source Directory (drive:\path or \\server\share\path), destination is Destination Directory (drive:\path or \\server\share\path) and file is File(s) to copy where names or wildcards can be specified and default is “*.*” (all files).

Robocopy Options and Switches
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.
/EFSRAW :: copy all encrypted files in EFS RAW mode.
/COPY:copyflag[s] :: what to COPY for files (default is /COPY:DAT).
(copyflags : D=Data, A=Attributes, T=Timestamps).
(S=Security=NTFS ACLs, O=Owner info, U=aUditing info).
/DCOPY:T :: COPY Directory Timestamps.
/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).
/SECFIX :: FIX file SECurity on all files, even skipped files.
/TIMFIX :: FIX file TIMes on all files, even skipped files.
/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).

Examples:
To use Robocopy is simple, just like how you would use Copy and Xcopy commands. For example, to copy entire folder of C:\Users to C:\UserBackup, simply type:
Robocopy C:\Users C:\UserBackup

来源

更多细节

答案4

尝试这个(在命令行上):

for /r "c:\my\source folder" %i in (*.pdf) do copy "%~fi" "c:\my\destination folder\%~nxi"

在资源管理器中:

...通过复制粘贴,您可以按下ctrl键将源文件夹拖到新的目的地。

相关内容