Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Current Files Location
  2. $files = Get-ChildItem 'C:\Users\MK\Desktop\Files' -Recurse | where {!$_.PsIsContainer}
  3.  
  4. # List Files which will be moved
  5. $files
  6.  
  7. # Files to be moved to
  8. $targetPath = 'C:\Users\MK\Desktop\Album'
  9.  
  10. foreach ($file in $files)
  11. {
  12. # YY-MM-DD
  13. $year = $file.LastWriteTime.Year.ToString()
  14. $month = $file.LastWriteTime.Month.ToString()
  15. $day = $file.LastWriteTime.Month.ToString()
  16.  
  17. # Out FileName, YY-MM-DD
  18. $file.Name
  19. $year
  20. $month
  21. $day
  22.  
  23. # Set Directory Path
  24. $Directory = $targetPath + "\" + $year + "\" + $month + "\" + $day
  25. # Create directory if it doesn't exsist
  26. if (!(Test-Path $Directory))
  27. {
  28. New-Item $directory -type directory
  29. }
  30.  
  31. # Move File to new location
  32. $file | Move-Item -Destination $Directory
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement