sort massive amounts of files into folder based on name?

Ryan711

[H]ard|Gawd
Joined
Nov 16, 2004
Messages
1,173
I've got a bunch of files that are all different names, but they have numbers appended on them. Example: filename_page1.jpg, filename_page2.jpg, filename_page3.jpg, etc.

What I would like to do is put these files that have the same name but different appending numbers into the same folder. So filename1_page1.jpg and filename1_page2.jpg would go into their own folder, and filename2_page1.jpg and filename2_page2.jpg would go into another folder.

I have 10s of thousands of these and am looking for something that can do this automatically. Does anyone know of a program that does this?
 
Use search to locate files that match a specific mask, then just copy/move those to a folder, move on and do a search for the next mask, copy/move those, etc. Seems pretty simple...

As for a piece of software, who knows, but Windows search will do that for you pretty easily.
 
As for a piece of software, who knows, but Windows search will do that for you pretty easily.

Seriously? One at a time for 10s of thousands of these??

Try Métamorphose. The UI is a bit quirky and you might have to learn rudimentary regular expressions to pull it off, but it can definitely do this.
 
But wait. Why can't you just order by filename in Explorer, then bulk select filename* and copy that to a separate folder?

How many versions of "filename*" do you have?
 
Seriously? One at a time for 10s of thousands of these??

Try Métamorphose. The UI is a bit quirky and you might have to learn rudimentary regular expressions to pull it off, but it can definitely do this.

I've been using Metamorphose since it first appeared, thank you very much. It's a file renaming tool - it is not designed to do what the OP is asking which is:

- sort files into groups based on filename
- copy/move said groups into folders based on those filenames

Metamorphose can move specific parts of a filename - say the first 3 characters - to the end or anyplace in the filename, like GUIfile001 becomes 001fileGUI and so on - but it's not a file copying/moving tool, sorry.

The best simplest solution is Windows search by the filename mask, specifically, and the files will appear in Explorer's pane - hit Control+A to highlight them all when the search is complete, drag 'em wherever the OP wants, done, next filename search, repeat. This ensures that no matter where the files are on the drive or the entire damned computer/network, they'll all get found and show up in a single list based on the specific filename mask used for that instance of search.

No "software" is needed to do something like this when Windows can do it easily, as previously stated.

Edit: Metamorphose can be used to help this situation... but it's not the solution, which I neglected to say the first time I typed this...
 
Last edited:
I've been using Metamorphose since it first appeared, thank you very much. It's a file renaming tool - it is not designed to do what the OP is asking which is:

- sort files into groups based on filename
- copy/move said groups into folders based on those filenames
You're right. I could have sworn I used it this way before, and since renaming and moving are logically identical I assumed my memory was correct.

The best simplest solution is Windows search by the filename mask, specifically, and the files will appear in Explorer's pane - hit Control+A to highlight them all when the search is complete, drag 'em wherever the OP wants, done, next filename search, repeat. This ensures that no matter where the files are on the drive or the entire damned computer/network, they'll all get found and show up in a single list based on the specific filename mask used for that instance of search.

No "software" is needed to do something like this when Windows can do it easily, as previously stated.
This is hardly a solution if OP has 10,000 (or even 50) different filename masks to deal with.
 
Well, he doesn't have 10,000+ different filenames, apparently his own statement of:

Ryan711 said:
So filename1_page1.jpg and filename1_page2.jpg would go into their own folder, and filename2_page1.jpg and filename2_page2.jpg would go into another folder.

covers that. Say for example he has several hundred files like this:

filename1_page1.jpg
filename1_page2.jpg
etc

all mixed in with hundreds of other files like...

filename2_page1.jpg
filename2_page2.jpg
filename3_page25.jpg
filename91_page2.jpg
etc

all sorts of various stuff, it doesn't matter. If he searches with a filename mask of:

filename1_page*.*

he's going to find only those files that match the first mask, obviously. Those will get grouped together as I explained, and he can then drag 'em into a new directory and never touch 'em again till he wants to rename them - that's where Metamorphose comes in.

I've never encountered a program that allowed you to do completely automagic filename sorting, grouping, renaming, etc - would be nice to point Windows to a folder, a drive, or an entire machine and say "Look, find all the jpgs, sort 'em into groups based on their filenames and keep it together, will ya."

Unfortunately, there's no way - my opinion, I could be wrong but I don't think that I am this time - to do this totally automagically, it's just not going to happen. User intervention is going to be required, like it or not.

Since we're not there on the OP's machine staring at the sheer number of files and the variety of the filenames, what I've suggested - followed up with your Metamorphose suggestion which I would have probably thrown in because it's a wicked evil cool program once you "get it" - can get the job done.

But a totally automagic "Hey, sort this shit for me, I'll be back later" app? Ain't happening... If such a thing exists, hell, point me to it and I'll grab the credit card. :D
 
You could write a vbscript to parse the file "prefix", create a directory with that prefix, and move the files into that directory. Actually -- powershell might be a better candidate. If you need a hand, send me a PM with some more detilas like -- are they all in the same directory, what is the file format, and anything else you can think of.
 
he's going to find only those files that match the first mask, obviously. Those will get grouped together as I explained, and he can then drag 'em into a new directory and never touch 'em again till he wants to rename them - that's where Metamorphose comes in.
I absolutely understand what you're explaining, you don't need to keep explaining it. It's a non-answer if the OP has lots of filename prefixes, and we don't know if he does or not. I assumed he did; if he's got 10,000s of them and only single digit numbers from his example, there are a minimum of 1000 and probably more.

Unfortunately, there's no way - my opinion, I could be wrong but I don't think that I am this time - to do this totally automagically, it's just not going to happen. User intervention is going to be required, like it or not.
It's a perl one-liner. Well okay, maybe a few lines, but pretty trivial. I'm sure there are other ways. It wouldn't be hard for the Metamorphose developers to modify it to do this either. I don't see why you think this is such a difficult problem that you can't set it up and let the computer handle the different sets of files. User intervention is requied to set it up initially, obviously, but if the filenames can be defined by a regular expression (looks like they can), there's no reason the computer can't do the rest.
 
Thanks for the replies guys. Unfortunately, doing the windows search method would be counter-productive at best.

What I've got is ~52,000 guitar pro tabs that I converted into images so that I could see the sheet music without having to install/open guitar pro to view them. Each tab has serveral pages, and the program outputs them in the format in the OP. On average, each tab has 4 pages which means that there are ~200k total files.

Someone mentioned being able to do this with pearl, could you link me to something or explain a little more. I know nothing about pearl, but learning it would be faster than trying to sort these by hand.
 
Powershell (and there is probably a better way to do it)
Code:
foreach ($file in get-item *.jpg)
{
  $dir = $file.name.tostring().substring(0,$file.name.indexof("_"))
  md $dir
  move $file $dir
}

You'll get a bunch of errors as it tries to create directories that already exists (after it creates it the first time), but I think it'll do the trick. Just install powershell, start it, and paste that code into it and you should be good. Or you can save it as a script and just run the script...

make sure you run it against a backup first to make sure -- I can't take responsibility for lost data!
 
Powershell (and there is probably a better way to do it)
Code:
foreach ($file in get-item *.jpg)
{
  $dir = $file.name.tostring().substring(0,$file.name.indexof("_"))
  md $dir
  move $file $dir
}

You'll get a bunch of errors as it tries to create directories that already exists (after it creates it the first time), but I think it'll do the trick. Just install powershell, start it, and paste that code into it and you should be good. Or you can save it as a script and just run the script...

make sure you run it against a backup first to make sure -- I can't take responsibility for lost data!

Wow, thanks man. Tested it out on a few files and worked perfectly. Thanks again.
 
Powershell (and there is probably a better way to do it)
Code:
foreach ($file in get-item *.jpg)
{
  $dir = $file.name.tostring().substring(0,$file.name.indexof("_"))
  md $dir
  move $file $dir
}

You'll get a bunch of errors as it tries to create directories that already exists (after it creates it the first time), but I think it'll do the trick. Just install powershell, start it, and paste that code into it and you should be good. Or you can save it as a script and just run the script...

make sure you run it against a backup first to make sure -- I can't take responsibility for lost data!
This works great but with problems if you have other files in the same Dir with different limiters ie. file-01.jpg, file_02.jpg here is my suggestion to work around this issue.
Code:
foreach ($file in get-item *_*.jpg)
{
  $dir = $file.name.tostring().substring(0,$file.name.indexof("_"))
  if (Test-Path $dir)
{
  move $file $dir
}
else
{
  md $dir
  move $file $dir
}
}

foreach ($file in get-item *-*.jpg)
{
  $dir = $file.name.tostring().substring(0,$file.name.indexof("-"))
  if (Test-Path $dir)
{
  move $file $dir
}
else
{
  md $dir
  move $file $dir
}
}
you can add as many blocks as you need to deal with the difference in limiters and adding the limiter to the wildcard statement will also prevent moving numbered files or files without limiters each into its own dir.
I also added an "if" statement the will check to see if the dir already exists, this prevents it from trying to re-create the dir eliminating the error issue and saving time on script execution.

hope this helps
 
Back
Top