Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

file - ROBOCOPY - Copy folders content to a single folder

Here is some code I made :)

@echo off
set source="R:Contracts"
set destination="R:ContractsSites"
ROBOCOPY %source% %destination% *.srt *.pdf *.mp4 *.jpg /COPYALL /R:0 /S
for /r %source in (*) do @copy "%destination" .

R:Contracts is full of folders which have files in them.

I want to copy all to R:ContractsSites and flatten the folder structure.

Everything copies well but also the folder structure.

Thank you

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You could do that with a PowerShell one liner. In this example I filter out all the files with the .txt extension from all the subfolders. And then send them to the Copy-Item Cmdlet.

Combine the Cmdlets Get-Childitem (GCI for short), -recurse, and -filter and then pipe the result to the Copy-Item Cmdlet. Use -WhatIf first to check that the output is what you expected.

Copy to another folder (Use -WhatIf and verify the output to check your command before committing to copying the files):

Get-Childitem -recurse R:Contracts -filter *.txt | Copy-Item -Destination R:ContractsSites -WhatIf

To do multiple filetypes as you've asked, you can just run multiple commands, one for each filetype.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...