Powershell is great (as am I) for automating boring little tasks.

So the question came to put 18 thousand plus image files that were in one folder into folders per year of Date created.

So to no longer keep you in suspense, here is the complete code

$SourceDir = “” $DestinationDir = “” Write-Host “Source directory: “ + $SourceDir Write-Host “Destination directory:” + $DestinationDir $files = get-childitem $SourceDir *.* -File |Select-Object -last 10 Write-Host “Number of files to move:” $files.Count foreach($file in $files) { $Directory = $DestinationDir + “\” + $file.LastWriteTime.Date.ToString(“yyyy”) if(!(Test-Path $Directory)) { Write-Host “Creating directory” New-Item $Directory -type directory } Write-Host “To directory:” $Directory Write-Host “Moving file:” $file.ToString() Move-Item $file.fullname $Directory Write-Host “File moved” } 

This only takes the last 10 files and it uses the LastWriteTime but you get the drift.

Just fill in the Source and Destination Directories and you’re good to go.

Most important parts.

$files = get-childitem $SourceDir *.* -File |Select-Object -last 10

Gets the files form the sourcedirectory and selects the last 10

$Directory = $DestinationDir + “\” + $file.LastWriteTime.Date.ToString(“yyyy”) if(!(Test-Path $Directory)) { Write-Host “Creating directory” New-Item $Directory -type directory }

Makes a new directory per year if it not already exists.

Move-Item $file.fullname $Directory

Moves the file.

Simple and quick. All 18k files moved in less than a minute.