Geeks With Blogs
BizTalk Blog by Chris Han System Design for Enterprise Agility,

It all started with letting iTunes "organize" my video files. For some reason, it decided to create a subfolder for each of my files. Errrrrrr!

Now I'm looking for a way to copy the files in subdirectories back to a single directory. By some online searching and error-trial, here's my solution:

For /r %d "C:\source dir" in (*) do copy "%d" "E:\dest dir"

It's different than a suggested solution I found online something like:

For /r %d "C:\source dir" in (.) do copy %d\*  "E:\dest dir"

However the period character doesn't work for me. According to the explaination, the (.) means all subdirectories, so the %d\* means all files in each subdirectories. But reality is it added a \.\ in the fully path name of the source, the result like this:

copy "C:\source dir\.\video.mp4" "E:\dest dir"

while it should be:

copy "C:\source dir\video.mp4" "E:\dest dir"

Any way, this format works for me, hopefully, same you some time.

For /r %d "C:\source dir" in (*) do copy "%d" "E:\dest dir"

 

Posted on Wednesday, January 6, 2010 9:54 PM The rest | Back to top


Comments on this post: How to copy all files in subdirectories without directory structure

# re: How to copy all files in subdirectories without directory structure
Requesting Gravatar...
Hi Chris,

When I ran on WinXP or Server 2003:
For /r %d "C:\whatever" in (*) do copy "%d" "E:\whatever"
I got the following error message:
"C:\whatever" was unexpected at this time.

Can you give me a hint what is wrong?

Thanks,
Vlad
Left by Vlad on Jan 08, 2010 12:50 PM

# re: How to copy all files in subdirectories without directory structure
Requesting Gravatar...
There is a wrong order of parameters.

Use the following command:

For /r "C:\source dir" %d in (*) do copy "%d" "E:\dest dir"

Instead of:

For /r %d "C:\source dir" in (*) do copy "%d" "E:\dest dir"
Left by Vlad on Jan 08, 2010 1:38 PM

# re: How to copy all files in subdirectories without directory structure
Requesting Gravatar...
Hi Chris,
Check out Biztalk Global job trends like No. of jobs in different countries, salary comparison, job roles, skills and exp. required at http://jobgraphs.com/biztalk/
Left by JobGraphs on Jul 17, 2010 9:37 AM

Your comment:
 (will show your gravatar)


Copyright © Chris Han | Powered by: GeeksWithBlogs.net