How can I recursively copy files of a specific pat

2019-01-12 21:37发布

I need to copy a set of DLL and PDB files from a set of folders recursively into another folder. I don't want to recreate the folder hierarchy in the target folder. I want to use built in Windows tools, e.g. DOS commands.

5条回答
趁早两清
2楼-- · 2019-01-12 22:09

command XCOPY

example of copying folder recursively:

mkdir DestFolder
xcopy SrcFolder DestFolder /E

(as stated below in the comment following WIKI that command was made available since DOS 3.2)

查看更多
Viruses.
3楼-- · 2019-01-12 22:12

Make sure that you have the quotes right if you have spaces in your path.

This is my postbuild event for my TFS build server (that is why there is "%%"). I needed all the test files to be copied over.

if not exist  "$(TargetDir)..\SingleFolderOutput" mkdir -p "$(TargetDir)..\SingleFolderOutput"

for /r **%%x** in (*.dll, *.pdb, *.xml, *.xaml, *.exe, *.exe.config) do xcopy **"%%x"** "$(TargetDir)..\SingleFolderOutput" /Y
查看更多
祖国的老花朵
4楼-- · 2019-01-12 22:13
@echo off
if %1'==' goto usage
if %2'==' goto usage
if %3'==' goto usage
for /D %%F in (%1\*) do xcopy %%F\%2 %3 /D /Y
for /D %%F in (%1\*.) do call TreeCopy %%F %2 %3
goto end
:usage
@echo Usage: TreeCopy [Source folder] [Search pattern] [Destination folder]
@echo Example: TreeCopy C:\Project\UDI *.xsd C:\Project\UDI\SOA\Deploy\Metadata
:end
查看更多
smile是对你的礼貌
5楼-- · 2019-01-12 22:30
mkdir targetDir
for /r %x in (*.dll, *pdb) do copy "%x" targetDir\

Use /Y at the end of the above command if you are copying multiple files and don't want to keep answering "Yes".

查看更多
虎瘦雄心在
6楼-- · 2019-01-12 22:32

I'm not aware of any command line tools that do this directly, but you could create a batch script to loop through sub folders, and copy the files you need.

However you may end up with files with duplicate filenames if you place them all in the same folder.

查看更多
登录 后发表回答