Far too many wallpaper images

I have accumulated a very large number of wallpaper images. It’s currently hovering around the 2k mark. This poses the small problem of me never seeing them. So, I’m going to create an automated wallpaper changer. But first, I need to organize them into folders based on aspect ratio. This is because I have dual monitors, which aren’t the same aspect ratio. Thus, I wrote a Powershell script that determines the ratio, and then moves the image into the appropriate subfolder.

   1:  #sorts the files inside $loc based on aspect ratio
   2:  $loc = "G:\my pics\wallpaper\"
   3:  
   4:  #set the location, and grab the files inside
   5:  Set-Location $loc
   6:  $folder = (New-Object -com ("Shell.Application")).NameSpace($loc)
   7:  
   8:  Get-ChildItem | foreach {
   9:      $item = $folder.ParseName($_)
  10:      #check that it's an image
  11:      if($item.Type -like "*image")
  12:      {
  13:          # get the width and height
  14:          $dim = $folder.GetDetailsOf($item, 31)
  15:          if($dim -match "(?<width>\d*)\sx\s(?<height>\d*)")
  16:          {
  17:              $aspect = [int]$matches.width / [int]$matches.height
  18:              #move based on aspect ratio bands
  19:              if(($aspect -le 1.4) -and ($aspect -ge 1.2))
  20:              {
  21:                  Move-Item -Path .\$_ -Destination .\Full\
  22:              }
  23:              elseif(($aspect -le 1.8) -and ($aspect -ge 1.5))
  24:              {
  25:                  Move-Item -Path .\$_ -Destination .\Wide\
  26:              }
  27:              else
  28:              {
  29:                  Move-Item -Path .\$_ -Destination .\Other\
  30:              }
  31:          }
  32:      }
  33:  }

It’s pretty simple code. It would be a lot harder to write if I had to write it in C#, however. Fear the power! 😛

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: