How can I move files from 2-level folders to 1-level folder

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.


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