Advertise here: Contact FM.


Easy Windows directory flattening with minimal tools?
May 9, 2007 7:15 PM   RSS feed for this thread Subscribe

I have a bunch of files, in a nested directory structure. I'd like to collapse the directory structure and move all the files into one folder, preferably sorting them by file extension or name. How do I do this as quickly and easily as possible in WinXP? (Using Cygwin is OK if that's the only way to do it.)

So, I have a bunch of music stored in the typical [Artistname]/[Albumname] hierarchy. It's a mix of formats. Some MP3, some WMA, some MP4 ... it's just generally a mess.

I want to sort it out. Basically, I want to pull ALL the music out of the nested folders and dump it in some other folder. Ideally I'd like to move all the files of a certain type into their own folder, so WMA files go in one folder, MP3s go into another, etc.

What's the easiest way to do this in Windows? Preferably without adding any additional software, although I'm OK with small freeware utilities or GPL tools like Cygwin (which I've been meaning to install anyway), although I keep thinking there has to be an easier way to do it than installing Cygwin and writing a shell script, which is the only solution I've come up with.
posted by Kadin2048 to computers & internet (7 comments total) 6 users marked this as a favorite
Using cygwin, this will put your MP3s in one dir, WMVs in another:

cd where_your_music_is
mkdir MP3
mkdir WMV
mv `find . -type f | grep -i mp3$` MP3
mv `find . -type f | grep -i mp3$` WMV

This will just put everything in a single dir:

mkdir STUFF
mv `find . -type f` STUFF

You might want to check that you have no duplicate filenames beforehand:

find . -type f | sed 's/.*\///' | sort | uniq -d

will print occurrences of duplicates.
posted by ldenneau at 7:29 PM on May 9, 2007


Try this: forfiles /s /p [path] /c "cmd /c move @file [newdir]"

No cygwin needed.
posted by sanko at 7:31 PM on May 9, 2007


If there are no dusplicates, this may work for you.

Go to the windows search window for the top level directory where your music is.

Do a search for * or *.*

All you files in the directory structure will appear.

Select them all, and copy and paste to your new directory.

You may have problems if there are files with the exact names.

Make sure you have a backup
posted by bottlebrushtree at 7:32 PM on May 9, 2007 [1 favorite]


Sorry, didn't read the entire post. Assuming you have a limited number of filetypes, just make a few passes with forfiles. So forfiles /s /m *.mp3 /p [path_to_mp3_files] /c "cmd /c move @file [newdir]"
posted by sanko at 7:33 PM on May 9, 2007


Grr. Sorry again, my brain is fried and I should learn how that preview button works. path_to_mp3_files belongs in the second set of brackets.
posted by sanko at 7:34 PM on May 9, 2007


Outstanding. Three different approaches, three workable solutions.

(My Linuxy heart likes ldenneau's the best but I'll probably try the Windows CLI and GUI approaches first, in the interest of not installing anything on this piece of junk that doesn't desperately need to be there.)

@sanko: I think I understand what you mean, but just to confirm, the command is:

forfiles /s /m *.mp3 /p [path-to-mp3-files] /c "cmd /c move @file [destination-dir]"

Where [path-to-mp3-files] and [destination-dir] are the root directory of the current hierarchy and the place where I'd like all the MP3 (or whatever) files deposited, respectively. Did I get that right?
posted by Kadin2048 at 7:43 PM on May 9, 2007


Kadin - that looks right to me. I haven't tried this though so you may want to sub copy for move just in case things go bad. If you did want to keep the structure, check out forfiles /? and look at the @relpath variable. Also note that you will have problems if there are any duplicate filenames.
posted by sanko at 7:49 PM on May 9, 2007


« Older A woman I greatly admire gave ...   |   Rough 10 months ahead of me...... Newer »

You are not logged in, either login or create an account to post comments



Related Questions
Looking for utility to list information about files. October 8, 2007
Need pointers: Efficient File System Organization December 15, 2005
clear out my cruft. November 16, 2005
Graphical volume cataloger? November 8, 2005
Need help organizing my digital life! March 29, 2005