Skip to content

Instantly share code, notes, and snippets.

@j-iNFINITE
Last active July 27, 2021 21:09
Show Gist options
  • Save j-iNFINITE/f6561da9afa4cd5daa903833a02b10c8 to your computer and use it in GitHub Desktop.
Save j-iNFINITE/f6561da9afa4cd5daa903833a02b10c8 to your computer and use it in GitHub Desktop.
powershell script for organize files in a folder,according to the year, month, day and extension
$path = "your folder path"
Set-Location $path
foreach ($file in (get-childitem $path | where { ! $_.PSIsContainer } ))
{
$year=$file.CreationTime.Year
$month=$file.CreationTime.Month
$day=$file.CreationTime.Day
$ext=($file.Extension).Trim(".")
$newpath=$path,$year,$month,$day,$ext -Join "\"
if (Test-Path $newpath){
Move-Item -literalpath $file $newpath}
Else {
md $newpath
Move-Item -literalpath $file $newpath}
}
@BobToninho
Copy link

Works amazingly! Is it possible to make it work for files inside folders of $path as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment