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.

I have a bunch of files stored in a file directory as such

root_folder
  -- folder1
     --folder1_2
       --bunch of files here
  -- folder2
     --folder2_2
       --bunch of files here
  -- folder3
     --folder3_2
       --bunch of files here

As you can see, my files in a 2-level folder from the root folder. How can I easily move my bunch of files as such the directory becomes like this:

root_folder
  -- folder1
     --bunch of files here
  -- folder2
     --bunch of files here
  -- folder3
     --bunch of files here

Is there any freeware program I can use? Or maybe can I use command prompt to accomplish this? Thanks a lot for the help :)

share|improve this question
    
What Operating System????? –  surfasb Jan 2 '12 at 1:16
    
windows 7 32-bit –  Nicholas Lie Jan 2 '12 at 13:35

3 Answers 3

I also provided a Powershell Example:

$source = "c:\sourceFolder"   
$dirs = dir $source | Where-Object {
$_.PSIsContainer }  

foreach ($folder in $dirs){  
    dir $folder -recurse | Where-Object { ! $_.PSIsContainer } | Move -Destination $folder -WhatIf  
     dir $folder -recurse | Where-Object { $_.PSIsContainer } | rd -recurse -Whatif  
}

You can copy and paste that into Powershell ISE. The bold whatif switches basically outputs a dry run.

You can check the output to make sure it is moving the files to where you exactly want them. Remove the -whatif switches to make script live.

share|improve this answer
    
i copy pasted your code and it gives the following error: Missing expression after unary operator '!'. At line:5 char:39 –  Nicholas Lie Jan 2 '12 at 13:41
    
@NicholasLie: Edit: I didn't format the code as code so some of the characters were unescaped. There should be an underscore after the $. –  surfasb Jan 2 '12 at 19:35

Powershell solution. Use this in root_folder (make sure that there aren't any loose files directly under root_folder):

gci -R | ?{!$_.PSIsContainer} | %{mv $_.fullname $_.directory.parent}

The above puts any file it finds into the same directory that the file's parent directory is in.

Then, to delete any now-empty folders:

gci -R | ?{(gci $_) -eq $NULL} | rm

share|improve this answer

In Explorer (assuming Windows here) open folder1_2, select all files, right click & choose Move to Folder ..., select Folder1 in the dialog; then delete folder1_2 if that was your intention.

Repeat the above for all subfolders you want to clear out.

No need for any external program.

share|improve this answer
1  
It would be ok if there's only 10 or so folders..If I have a 100+ folders it would cumbersome for me to do so (which in my case 200+ folders) >,< –  Nicholas Lie Jan 3 '12 at 4:25

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.