Home » Questions » Computers [ Ask a new question ]

Get rid of subfolders while keeping their contents?

Get rid of subfolders while keeping their contents?

In Windows, is there a way (built in or using a 3rd party program) to bulk move all the contents of subfolders up a level? In other words, a way to get rid of selected subfolders while keeping their contents? I'd like to go from:

Asked by: Guest | Views: 19
Total answers/comments: 2
Guest [Entry]

"You can use a for loop in the command prompt:

for /r %i in (*) do @move ""%i"" .

Yes, it will try to move files in the current directory, back to the current directory, but that doesn't cause any harm. Make sure you run it while situated in the top of the hierarchy you want to move the files to. Running this from another location will have very undesired effects.

If you wish to run it so that you do not have to be in a certain directory, you can type out the paths:

for /r C:\path %i in (*) do @move ""%i"" ""C:\path""

replace C:\path with the location of the top directory that all the files will be moved to. If you wish to run it in a batch script, change the variables to include another percent sign:

for /r C:\path %%i in (*) do @move ""%%i"" ""C:\path""

to remove all of the empty subdirectories (from cmd):

for /d %i in (C:\path\*) do @rmdir /s /q ""%i""

from batch:

for /d %%i in (C:\path\*) do @rmdir /s /q ""%%i"""
Guest [Entry]

Loads of good suggestions so far. You could also use Everything. Right click on the relevant parent folder, "search everything". This will give a list of, well, everything in the folder. You can perform the moving operations from here, perhaps after sorting by file type, or including a file type in the search, to exclude the folders.