PowerShell Script to Sort Your Photos into "YYYY-MM-DD" folders by the date they were created
This 3-liner will read the folder where you have many pictures. Then it will read the date pictures/files were created and create a new folder (Ex: 2016-12-31).
Then it will move corresponding pictures into this folder. So you will have all the pictures sorted out into the folders with corresponding date.
$DestRootDir="C:\Users\MyUsername\Pictures\"
$fotos = Get-ChildItem $DestRootDir | ? {!$_.PSIsContainer} | Group-object -Property @{Expression={$_.CreationTime.ToString("yyyy-MM-dd")}} -AsHashTable -AsString
$fotos.GetEnumerator() | % {New-Item -Path $($DestRootDir+$_.Key) -ItemType Directory; $dest=$DestRootDir + $_.Key ; $_.Value | % {Move-Item $($DestRootDir+$_.Name) -Destination $dest} }
BEFORE:
C:\Pictures
File1.jpg (created Nov 24 2015)
File2.jpg (created Nov 24 2015)
File3.jpg (created Dec 31 2015)
...
File100.jgp (created Jan 1 2016)
AFTER:
C:\Pictures
2015-11-24
File1.jpg (created Nov 24 2015)
File2.jpg (created Nov 24 2015)
2015-12-31
File3.jpg (created Dec 31 2015)
2016-01-01
File100.jgp (created Jan 1 2016)
Then it will move corresponding pictures into this folder. So you will have all the pictures sorted out into the folders with corresponding date.
$DestRootDir="C:\Users\MyUsername\Pictures\"
$fotos = Get-ChildItem $DestRootDir | ? {!$_.PSIsContainer} | Group-object -Property @{Expression={$_.CreationTime.ToString("yyyy-MM-dd")}} -AsHashTable -AsString
$fotos.GetEnumerator() | % {New-Item -Path $($DestRootDir+$_.Key) -ItemType Directory; $dest=$DestRootDir + $_.Key ; $_.Value | % {Move-Item $($DestRootDir+$_.Name) -Destination $dest} }
BEFORE:
C:\Pictures
File1.jpg (created Nov 24 2015)
File2.jpg (created Nov 24 2015)
File3.jpg (created Dec 31 2015)
...
File100.jgp (created Jan 1 2016)
AFTER:
C:\Pictures
2015-11-24
File1.jpg (created Nov 24 2015)
File2.jpg (created Nov 24 2015)
2015-12-31
File3.jpg (created Dec 31 2015)
2016-01-01
File100.jgp (created Jan 1 2016)
Comments
Post a Comment