Skip to content

Instantly share code, notes, and snippets.

@csereno
Last active January 5, 2019 04:59
Show Gist options
  • Save csereno/2ebdf5d8363b42746064766970db124e to your computer and use it in GitHub Desktop.
Save csereno/2ebdf5d8363b42746064766970db124e to your computer and use it in GitHub Desktop.
<#
Script to move photos from Plex upload to folders organized by date
File modified for multiple folders by csereno as taken from: https://stackoverflow.com/questions/21103613/powershell-script-to-move-files-into-year-month-folders-based-on-creation-timest
Set Variables of Source folder(s) and Destination folder
Assign variable of files
For each file assign the Directory variable the information for file creation year and month
if the year and month folder do not exist, then create them from file creation information
Move file to sub-folder of year and month from file creation information passed into Directory variable
#>
#Set Destination
$DestinationDir = "YOUR_DESTINATION\"
#Set Sources in hash table
$src_dirs = @{dir1 = "SOURCE_1\";
dir2 = "SOURCE_2\"}
#Start file with date
echo $(Get-Date) "Beginning photo moves" | Out-File -FilePath 'PATH\TO\LOGFILE.log'
#Enumerate the directories
ForEach($dir in $src_dirs.GetEnumerator()) {
$files = get-childitem $dir.Value *
#Analyze and move the files
ForEach ($file in $files) {
$Directory = $DestinationDir + "" + $file.LastWriteTime.Date.ToString('yyyy') + "\" + $file.LastWriteTime.ToString('MM-MMM-yyyy')
#Test if the directory path exists
if (!(Test-Path $Directory)) {
New-Item $directory -type directory
}
Move-Item $file.fullname $Directory -Verbose *>&1 | Out-File -FilePath 'PATH\TO\LOGFILE.log' -Append
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment