Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Current Files Location
- $files = Get-ChildItem 'C:\Users\MK\Desktop\Files' -Recurse | where {!$_.PsIsContainer}
- # List Files which will be moved
- $files
- # Files to be moved to
- $targetPath = 'C:\Users\MK\Desktop\Album'
- foreach ($file in $files)
- {
- # YY-MM-DD
- $year = $file.LastWriteTime.Year.ToString()
- $month = $file.LastWriteTime.Month.ToString()
- $day = $file.LastWriteTime.Month.ToString()
- # Out FileName, YY-MM-DD
- $file.Name
- $year
- $month
- $day
- # Set Directory Path
- $Directory = $targetPath + "\" + $year + "\" + $month + "\" + $day
- # Create directory if it doesn't exsist
- if (!(Test-Path $Directory))
- {
- New-Item $directory -type directory
- }
- # Move File to new location
- $file | Move-Item -Destination $Directory
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement