Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #Before running script execute this set-executionpolicy remotesigned
  2.  
  3. # Wzorzec nazwy katalogu np. 2019_03_02
  4. $name_pattern = "yyyy_MM_dd"
  5.  
  6. # Katalog wejsciowy bez '\' na koncu
  7. $source = "c:\Users\Domownik\Documents\ps1"
  8.  
  9. # Katalog wyjsciowy KONIECZNIE z '\' na koncu
  10. $destination = "c:\Users\Domownik\Documents\ps1\"
  11.  
  12. $shell = New-Object -ComObject Shell.Application
  13. $folder = $shell.namespace($source)
  14.  
  15. clear
  16. Write-Host "Tworzenie katalogow i kopiowanie plików... To moze chwile zajac."
  17.  
  18. Get-ChildItem $source | ForEach-Object {
  19. $_.Name
  20. $item = $folder.Items().Item($_.Name).ExtendedProperty("System.Photo.DateTaken")
  21. $date = $_.LastWriteTime.ToString($name_pattern)
  22.  
  23. if($_.FullName -match "img_\d+_"){
  24. $filename = $_.FullName -split '_'
  25. $date = [datetime]::ParseExact($filename[1], 'yyyyMMdd', $null).ToString($name_pattern)
  26. }
  27.  
  28. if($item){
  29. $date = $item.ToString($name_pattern)
  30. }
  31.  
  32. $path = $destination + $date
  33.  
  34. if(!(Test-Path $path)){
  35. mkdir $path > $null
  36. }
  37.  
  38. Copy-Item -Path $_.FullName -Destination $path
  39. }
  40. Write-Host "Gotowe."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement