Sorting photos via powershell v1

I have a drive full of photos – over 300GB – that are sorted into folders for each location photographed. The folder name is a location code of sorts.  While NTFS can have billions of files in a folder, explorer will seize up for minutes as it retrieves data for this drive.

I needed a way to sort my folders into subfolders, just to speed up browsing the drive.  If a location code was DJKSASWW, I wanted that sorted into a folder name DJKS.  This would group much smaller sets of data and still allow for an intelligent, browseable structure if human intervention was necessary.

Powershell came thorough for me.

# source location of folder to copy/move
$source = "E:IMAGEVAULT"

# where we want these to wind up
$destination = "R:imagevault"

# get our objects (this is filtered for just those that start
# with the letter 'a' right now
$folders = Get-ChildItem -filter A* $source

# loop each folder object from our source
foreach ($folder in $folders){
    # the this specific folder name
    $foo = $
    # new folder name is going to be the first 4 characters
    $newfolder = [char]$foo[0]+[char]$foo[1]+[char]$foo[2]+[char]$foo[3]
    # set the path to this new destination folder
    $newDest = $destination + $newfolder

    # test to see if this path exists
    if(Test-Path $newDest)
        {   # it does so we will show what we're copying/moving
            $folder.FullName + " to " + $newDest
            # and perform the task
            Copy-Item $folder.FullName $newDest -recurse
        } else {
            # create path since it didn't exist
            New-Item $newDest -Type Directory
            # show what we're copying/moving
            $folder.FullName + " to " + $newDest
            # and perform the task
            Copy-Item $folder.FullName $newDest -recurse

This allows me to set a source and destination and the script (while time consuming) will fix the entire structure.

All you'd have to do is change Copy-Item to Move-Item if you didn't want a 2nd set.

Comments Closed.