Last active
July 27, 2021 21:09
-
-
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
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
$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} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works amazingly! Is it possible to make it work for files inside folders of $path as well?