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 :)

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

3 Answers

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.

link|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 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 at 19:35
feedback

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

link|improve this answer
feedback

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.

link|improve this answer
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 at 4:25
feedback

Your Answer

 
or
required, but never shown

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