Get rid of subfolders while keeping their contents?

5

7

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:

Folder
  Subfolder1
    File1
  Subfolder2
    File2

To:

Folder
  File1
  File2

In a single process.

George MacDonald

Posted 2009-12-21T02:30:47.133

Reputation: 53

Answers

6

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"

John T

Posted 2009-12-21T02:30:47.133

Reputation: 149 037

I felt forced to edit your post as what you proposed would result in pretty nasty file loss. First, using delims=? is dangerous since the default settings of console windows on Windows use raster fonts which cause every Unicode character that doesn't fit into the legacy OEM codepage to be printed as ?. And you were iterating over output ... Using for /f is the wrong idiom anyway here. for can iterate over files, recursively or directories just fine and it will correctly handle Unicode filenames even with raster fonts. 600 chars is to short for a proper explanation of the subject :-( – Joey – 2009-12-21T08:24:34.467

forgot about unicode :( thanks though. – John T – 2009-12-21T18:47:54.040

By the way, "delims=" is perfectly acceptable and works. You don't have to find a character that is unlikely in the output :-) – Joey – 2009-12-22T08:00:49.997

3

A simple way (in XP) is to right click on the root folder and select Search, then enter no criteria and press Search. The search results will be a flattened list of what's in the folder and subfolders. You can then just drag the results of the search into another folder and all the files will be "removed" from their folders.

In versions of Windows after XP you can achieve the same effect by just entering a search term in the search box on the top right of an Explorer Window, and then copying the results to another folder.

Matthew Lock

Posted 2009-12-21T02:30:47.133

Reputation: 4 254

Is this Search command a right click option? And is it only in XP and not in Vista or 7? – George MacDonald – 2009-12-22T14:48:54.520

1

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.

outsideblasts

Posted 2009-12-21T02:30:47.133

Reputation: 6 297

"Everything" is great. The "content" style searches in Vista onwards aren't as good as exhausted search by file name. – Matthew Lock – 2014-03-26T00:16:45.120

0

You could do this using batch files and the 'move' command.

have a read of this thread.

JT.WK

Posted 2009-12-21T02:30:47.133

Reputation: 1 928

0

You can get Total Commander, which is a shareware file management program, go into your folder, press Ctrl + B (meaning branch all subdirectories - it will display all files in this directory and all subdirectories), select everything and copy to your desired location (i.e. one folder higher).

GregC

Posted 2009-12-21T02:30:47.133

Reputation: 459