Skip to content

Instantly share code, notes, and snippets.

@jimdi
Created September 24, 2021 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimdi/9129e2509f92f7ddeca4ba18e80b8d77 to your computer and use it in GitHub Desktop.
Save jimdi/9129e2509f92f7ddeca4ba18e80b8d77 to your computer and use it in GitHub Desktop.
#$files = Get-ChildItem 'Z:\Camera Uploads' -Recurse | where {!$_.PsIsContainer}
$files = Get-ChildItem 'Z:\Camera Uploads' | where {!$_.PsIsContainer}
# List Files which will be moved
$files
# Target Filder where files should be moved to. The script will automatically create a folder for the year and month.
$targetPath = 'Z:\Camera Uploads\Albums'
foreach ($file in $files)
{
# Get year and Month of the file
# I used LastWriteTime since this are synced files and the creation day will be the date when it was synced
$year = $file.LastWriteTime.Year.ToString()
$month = $file.LastWriteTime.Month.ToString()
# Out FileName, year and month
$file.Name
$year
$month
# Set Directory Path
$Directory = $targetPath + "\" + $year + "\" + $month
# Create directory if it doesn't exsist
if (!(Test-Path $Directory))
{
New-Item $directory -type directory
}
# Move File to new location
$file | Move-Item -Force -Destination $Directory
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment