Created
September 24, 2021 13:39
-
-
Save jimdi/9129e2509f92f7ddeca4ba18e80b8d77 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#$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