Guest User

Untitled

a guest
Apr 25th, 2013
1,121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $a=[reflection.assembly]::LoadWithPartialName("System.Drawing")
  2.  
  3.  
  4. $paths = Get-ChildItem -Recurse -Filter "*.jpg" "f:\photo\"
  5.  
  6. $date = Get-Date "1.1.2013"
  7. #$paths = $paths | ? {$_.CreationTime -lt $date}
  8. #$paths = @($paths[0])
  9.  
  10. function Get-DateTaken($path){
  11.     $pic = New-Object System.Drawing.Bitmap($path)
  12.     try{
  13.         $bytes = $pic.GetPropertyItem(36867).Value
  14.         $ExifDtString=[System.Text.Encoding]::ASCII.GetString($bytes)
  15.         [datetime]::ParseExact($ExifDtString,"yyyy:MM:dd HH:mm:ss`0",$Null)
  16.     }
  17.     finally{
  18.         $pic.Dispose()
  19.     }
  20. }
  21.  
  22. $c = 0;
  23. $t = $paths.Count
  24. $date = 0
  25. foreach ($item in $paths){
  26.     Write-Progress -Activity "Update date" -status "dd" -PercentComplete (($c++)/$t*100)
  27.      
  28.     try {
  29.         $date = Get-DateTaken $item.FullName
  30.         $date = New-Object datetime -ArgumentList $date.Ticks,([System.DateTimeKind]::Local)
  31.        
  32.         $item.LastWriteTime = $date
  33.     }
  34.     catch{
  35.         Write-Warning "item $($item.FullName) skipped.`n   $($error[0])`n"
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment