# CMD Resolution Sorter



## beesagtig (Jan 17, 2009)

Hey

I'm trying to make a simple batch program to sort background's into folders depending on their resolution and want to know how do you get the batch to check the resolution?

Thanks


----------



## FordGT90Concept (Jan 17, 2009)

A batch can't check resolutions.  I think the only way you could achieve that with a batch is to have a program rename all the files placing the resolution in the name (e.g. file.jpg -> 01200x00768-file.jpg).

It wouldn't be too hard to create a small app that does this for you.


----------



## beesagtig (Jan 17, 2009)

ok thanks

what should I use to change the names?


----------



## Deleted member 3 (Jan 17, 2009)

Use 3rd party tools to read file details like resolutions.


----------



## IggSter (Jan 17, 2009)

It's possible that IrfanView could do what you are looking for, I certainly know it can batch process images for resizing etc so maybe copy/move is an option also.


----------



## FordGT90Concept (Jan 17, 2009)

What kind of files are these (JPG, PNG, etc.)?   I could make something to do what you are asking but it probably wouldn't be available until Monday at the earliest.


----------



## beesagtig (Jan 17, 2009)

really? that would be awesome. They are mostly jpegs.


----------



## FordGT90Concept (Jan 18, 2009)

What specific criteria do you want me to implement?  Like...

if height < 100 and width < 200 move to "small" folder
if height > 4000 and width > 6000 move to "large" folder

...or, I could just make one folder per resolution.


----------



## beesagtig (Jan 18, 2009)

one folder per resolution would be great thanks


----------



## FordGT90Concept (Jan 18, 2009)

Just extract it to the directory you want to sort and run it.  It will create one directory per resolution and copy files to them (read: not move so the originals will still be there).  The folders will be named 00000x00000 (width x height).  Requires .NET 3.5 to run.


----------



## beesagtig (Jan 18, 2009)

Thankyou very much. works great


----------



## FordGT90Concept (Jan 18, 2009)

The source, if anyone cares for it...

```
using System;
using System.Drawing;
using System.IO;
using System.Reflection;

namespace PicSort
{
    class Program
    {
        static void Main(string[] args)
        {
            string dir = "";
            if (args.Length == 0)
                dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase).Substring(6);
            if (args.Length == 1)
                dir = args[0];

            if (Directory.Exists(dir))
            {
                string[] types = new string[] { "*.jpg", "*.png", "*.bmp" };
                for (int i = 0; i < types.Length; i++)
                {
                    string[] files = Directory.GetFiles(dir, types[i]);
                    foreach (string file in files)
                    {
                        FileInfo fi = new FileInfo(file);
                        Image img = Image.FromFile(fi.FullName);
                        string newdir = dir + "\\" + img.Width.ToString().PadLeft(5, '0') + "x" + img.Height.ToString().PadLeft(5, '0');
                        Directory.CreateDirectory(newdir);
                        File.Copy(fi.FullName, newdir + "\\" + fi.Name, true);
                    }
                }
            }
            else
                Console.WriteLine("PicSort [directory to sort]");
        }
    }
}
```


----------

