Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Given a folder with several subdirectories, I want to move their contents to the top folder and remove the subdirectories. How can I do that on the Windows command line?

E.g. I have a folder named "Jack" in D:. It contains several subfolders and each subdirectory contains additional files (text files, PDF files, etc.), but no directories. I want to move all subfolders' files into "Jack", and remove the then empty subdirectories. If duplicate file found do replace or do nothing, I need only one copy I need to do this repeatedly, so a batch solution would be best.

share|improve this question
    
Welcome to Super User! Please take a moment to read the FAQ to learn how the site works. –  Daniel Beck Oct 9 '12 at 5:18
4  
How do you want to deal with naming collisions? Will there be D:\Jack\A\1.pdf and D:\Jack\B\1.pdf? –  Daniel Beck Oct 9 '12 at 5:18
    
thanks, I am using these at office, File names are different, If same filename found just replace, Thanks in advnce Mr. Beck –  Nikhil Oct 9 '12 at 6:39
    
"If same filename found just replace"... to what? –  Siva Charan Oct 9 '12 at 6:51
1  
You can use xcopy to do this. Type xcopy /? at the command prompt for usage information. –  martineau Oct 9 '12 at 7:17

1 Answer 1

Put this in a batch script.

for /f "delims==" %%k in ('dir D:\Jack\*.* /s /b') do copy "%%k" D:\Jack\ /Y
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.