Skip to content

Instantly share code, notes, and snippets.

@jtmoon79
Last active July 8, 2022 22:59
Show Gist options
  • Save jtmoon79/eea39c3f9b3d37a169286da8f7788512 to your computer and use it in GitHub Desktop.
Save jtmoon79/eea39c3f9b3d37a169286da8f7788512 to your computer and use it in GitHub Desktop.

Revisions

  1. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -78,6 +78,7 @@ function ProcessJPG
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    #
    # XXX: the camera picture file embedded tagging varies tremendously; this works for my
    # set of .jpg files
    & "$exiftool" -verbose -verbose -extractEmbedded `
  2. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -52,11 +52,12 @@ function PrintDates

    # functions Process*
    # set the file system file attributes (`File:FileAccessDate` is typically not writable)
    #
    # XXX: `File:FileAccessDate` sometimes ends up matching the last changed datetime value,
    # i.e. a change to `File:FileModifyDate` has a side-affect of setting `File:FileAccessDate`
    # to the same value.

    # BUG: `File:FileCreateDate` often fails to change, will this help?
    #
    # BUG: `File:FileCreateDate` often fails to change, will `ForceCreateDate` help?
    # most likely failure is due to the file being on a Unix Samba share, and
    # the Samba share settings disallowing this change due to some combination
    # of factors
  3. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -57,7 +57,7 @@ function PrintDates
    # to the same value.

    # BUG: `File:FileCreateDate` often fails to change, will this help?
    # most likely failiure is due to the file being on a Unix Samba share, and
    # most likely failure is due to the file being on a Unix Samba share, and
    # the Samba share settings disallowing this change due to some combination
    # of factors
    function ForceCreateDate {
  4. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -57,8 +57,9 @@ function PrintDates
    # to the same value.

    # BUG: `File:FileCreateDate` often fails to change, will this help?
    # most likely failiure is due to the file being on a Unix Samba share, and so
    # some loss in translation Windows SMB -> Unix SMB
    # most likely failiure is due to the file being on a Unix Samba share, and
    # the Samba share settings disallowing this change due to some combination
    # of factors
    function ForceCreateDate {
    Param(
    [Parameter(Mandatory=$true)][String]$file
  5. jtmoon79 revised this gist Jul 8, 2022. No changes.
  6. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -56,8 +56,8 @@ function PrintDates
    # i.e. a change to `File:FileModifyDate` has a side-affect of setting `File:FileAccessDate`
    # to the same value.

    # BUG: `File:FileCreateDate` often fails to change
    # most likely due to the file being on a Unix Samba share, and so
    # BUG: `File:FileCreateDate` often fails to change, will this help?
    # most likely failiure is due to the file being on a Unix Samba share, and so
    # some loss in translation Windows SMB -> Unix SMB
    function ForceCreateDate {
    Param(
  7. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,9 @@ function PrintDates
    # i.e. a change to `File:FileModifyDate` has a side-affect of setting `File:FileAccessDate`
    # to the same value.

    # BUG: `File:FileCreateDate` often fails to change, will this help?
    # BUG: `File:FileCreateDate` often fails to change
    # most likely due to the file being on a Unix Samba share, and so
    # some loss in translation Windows SMB -> Unix SMB
    function ForceCreateDate {
    Param(
    [Parameter(Mandatory=$true)][String]$file
  8. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -55,8 +55,8 @@ function PrintDates
    # XXX: `File:FileAccessDate` sometimes ends up matching the last changed datetime value,
    # i.e. a change to `File:FileModifyDate` has a side-affect of setting `File:FileAccessDate`
    # to the same value.
    # BUG: `File:FileCreateDate` often fails to change

    # BUG: `File:FileCreateDate` often fails to change, will this help?
    function ForceCreateDate {
    Param(
    [Parameter(Mandatory=$true)][String]$file
  9. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -57,6 +57,14 @@ function PrintDates
    # to the same value.
    # BUG: `File:FileCreateDate` often fails to change

    function ForceCreateDate {
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    $date_lastwritetime = (Get-Item $file).LastWriteTime
    (Get-Item $file).CreationTime = $date_lastwritetime
    }

    function ProcessJPG
    {
    Param(
  10. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -134,7 +134,7 @@ try {
    ProcessMP4 $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed single .mov file
    # user passed single .avi file
    } elseif ((Test-Path -Path $Path -PathType Leaf) -AND $Path.EndsWith(".avi", $compare)) {
    # see datetime attributes before
    PrintDates $Path
  11. jtmoon79 revised this gist Jul 8, 2022. No changes.
  12. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -46,7 +46,7 @@ function PrintDates
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    Write-Verbose "$exiftool -time:all -groupHeadings -short -duplicates $file"
    Write-Verbose "$exiftool -time:all -groupHeadings -short -duplicates '$file'"
    & "$exiftool" -time:all -groupHeadings -short -duplicates $file
    }

    @@ -62,7 +62,7 @@ function ProcessJPG
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    Write-Verbose "$exiftool $file"
    Write-Verbose "$exiftool '$file'"
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    @@ -81,7 +81,7 @@ function ProcessMP4
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    Write-Verbose "$exiftool $file"
    Write-Verbose "$exiftool '$file'"
    # set the file system file attributes (`File:FileAccessDate` is typically not writable)
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-Quicktime:CreateDate>File:FileCreateDate' `
    @@ -94,7 +94,7 @@ function ProcessAVI
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    Write-Verbose "$exiftool $file"
    Write-Verbose "$exiftool '$file'"
    # set the file system file attributes (`File:FileAccessDate` is typically not writable)
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-RIFF:DateTimeOriginal>File:FileCreateDate' `
  13. jtmoon79 revised this gist Jul 8, 2022. No changes.
  14. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -66,7 +66,7 @@ function ProcessJPG
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    # XXX: the camera picture file embedded tagging varies tremendously among cameras; this works for my
    # XXX: the camera picture file embedded tagging varies tremendously; this works for my
    # set of .jpg files
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-EXIF:DateTimeOriginal>File:FileCreateDate' `
  15. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -66,7 +66,7 @@ function ProcessJPG
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    # XXX: the approach to camera picture file embedded tagging varies tremendously; this works for my
    # XXX: the camera picture file embedded tagging varies tremendously among cameras; this works for my
    # set of .jpg files
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-EXIF:DateTimeOriginal>File:FileCreateDate' `
  16. jtmoon79 revised this gist Jul 8, 2022. No changes.
  17. jtmoon79 revised this gist Jul 8, 2022. No changes.
  18. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -66,6 +66,8 @@ function ProcessJPG
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    # XXX: the approach to camera picture file embedded tagging varies tremendously; this works for my
    # set of .jpg files
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-EXIF:DateTimeOriginal>File:FileCreateDate' `
    '-EXIF:CreateDate>File:FileCreateDate' `
  19. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 7 additions and 2 deletions.
    9 changes: 7 additions & 2 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -50,17 +50,22 @@ function PrintDates
    & "$exiftool" -time:all -groupHeadings -short -duplicates $file
    }

    # functions Process*
    # set the file system file attributes (`File:FileAccessDate` is typically not writable)
    # XXX: `File:FileAccessDate` sometimes ends up matching the last changed datetime value,
    # i.e. a change to `File:FileModifyDate` has a side-affect of setting `File:FileAccessDate`
    # to the same value.
    # BUG: `File:FileCreateDate` often fails to change

    function ProcessJPG
    {
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    Write-Verbose "$exiftool $file"
    # set the file system file attributes (`File:FileAccessDate` is typically not writable)
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    # BUG: `File:FileCreateDate` often fails to change
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-EXIF:DateTimeOriginal>File:FileCreateDate' `
    '-EXIF:CreateDate>File:FileCreateDate' `
  20. jtmoon79 revised this gist Jul 8, 2022. No changes.
  21. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -82,7 +82,7 @@ function ProcessMP4
    $file
    }

    function ProcessMOV
    function ProcessAVI
    {
    Param(
    [Parameter(Mandatory=$true)][String]$file
    @@ -128,10 +128,10 @@ try {
    # see datetime attributes after
    PrintDates $Path
    # user passed single .mov file
    } elseif ((Test-Path -Path $Path -PathType Leaf) -AND $Path.EndsWith(".mov", $compare)) {
    } elseif ((Test-Path -Path $Path -PathType Leaf) -AND $Path.EndsWith(".avi", $compare)) {
    # see datetime attributes before
    PrintDates $Path
    ProcessMOV $Path
    ProcessAVI $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed directory
    @@ -145,9 +145,9 @@ try {
    Get-ChildItem $Path -Recurse -File -Filter "*.mp4" `
    | Sort-Object -Property FullName `
    | ForEach-Object { ProcessMP4 $_ }
    Get-ChildItem $Path -Recurse -File -Filter "*.mov" `
    Get-ChildItem $Path -Recurse -File -Filter "*.avi" `
    | Sort-Object -Property FullName `
    | ForEach-Object { ProcessMOV $_ }
    | ForEach-Object { ProcessAVI $_ }
    # user passed unhandled file
    } else {
    Write-Error "Unhandled file $Path"
  22. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -134,7 +134,7 @@ try {
    ProcessMOV $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed directory
    # user passed directory
    } elseif (Test-Path -Path $Path -PathType Container) {
    Get-ChildItem $Path -Recurse -File -Filter "*.jpg" `
    | Sort-Object -Property FullName `
  23. jtmoon79 revised this gist Jul 8, 2022. No changes.
  24. jtmoon79 revised this gist Jul 8, 2022. No changes.
  25. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 11 additions and 8 deletions.
    19 changes: 11 additions & 8 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -128,14 +128,14 @@ try {
    # see datetime attributes after
    PrintDates $Path
    # user passed single .mov file
    } elseif ((Test-Path -Path $Path -PathType Leaf) -AND $Path.EndsWith(".mov", $compare)) {
    # see datetime attributes before
    PrintDates $Path
    ProcessMOV $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed directory
    } elseif (Test-Path -Path $Path -PathType Container) {
    } elseif ((Test-Path -Path $Path -PathType Leaf) -AND $Path.EndsWith(".mov", $compare)) {
    # see datetime attributes before
    PrintDates $Path
    ProcessMOV $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed directory
    } elseif (Test-Path -Path $Path -PathType Container) {
    Get-ChildItem $Path -Recurse -File -Filter "*.jpg" `
    | Sort-Object -Property FullName `
    | ForEach-Object { ProcessJPG $_ }
    @@ -145,6 +145,9 @@ try {
    Get-ChildItem $Path -Recurse -File -Filter "*.mp4" `
    | Sort-Object -Property FullName `
    | ForEach-Object { ProcessMP4 $_ }
    Get-ChildItem $Path -Recurse -File -Filter "*.mov" `
    | Sort-Object -Property FullName `
    | ForEach-Object { ProcessMOV $_ }
    # user passed unhandled file
    } else {
    Write-Error "Unhandled file $Path"
  26. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -135,7 +135,7 @@ try {
    # see datetime attributes after
    PrintDates $Path
    # user passed directory
    } elseif (Test-Path -Path $Path -PathType Container) {
    } elseif (Test-Path -Path $Path -PathType Container) {
    Get-ChildItem $Path -Recurse -File -Filter "*.jpg" `
    | Sort-Object -Property FullName `
    | ForEach-Object { ProcessJPG $_ }
  27. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -127,6 +127,13 @@ try {
    ProcessMP4 $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed single .mov file
    } elseif ((Test-Path -Path $Path -PathType Leaf) -AND $Path.EndsWith(".mov", $compare)) {
    # see datetime attributes before
    PrintDates $Path
    ProcessMOV $Path
    # see datetime attributes after
    PrintDates $Path
    # user passed directory
    } elseif (Test-Path -Path $Path -PathType Container) {
    Get-ChildItem $Path -Recurse -File -Filter "*.jpg" `
  28. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 13 additions and 0 deletions.
    13 changes: 13 additions & 0 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -82,6 +82,19 @@ function ProcessMP4
    $file
    }

    function ProcessMOV
    {
    Param(
    [Parameter(Mandatory=$true)][String]$file
    )
    Write-Verbose "$exiftool $file"
    # set the file system file attributes (`File:FileAccessDate` is typically not writable)
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-RIFF:DateTimeOriginal>File:FileCreateDate' `
    '-RIFF:DateTimeOriginal>File:FileModifyDate' `
    $file
    }

    try {
    # XXX: fallback path is hardcoded to my location
    $exiftool = "$HOME\Apps\exiftool-12.42\exiftool.exe"
  29. jtmoon79 revised this gist Jul 8, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions set-datetime-of-pics-vids.ps1
    Original file line number Diff line number Diff line change
    @@ -60,6 +60,7 @@ function ProcessJPG
    # first use `EXIF:DateTimeOriginal` which is sometimes available and sometimes correct
    # then use `EXIF:CreateDate` which is sometimes avilable and often correct
    # hopefully the most appropriate date is used
    # BUG: `File:FileCreateDate` often fails to change
    & "$exiftool" -verbose -verbose -extractEmbedded `
    '-EXIF:DateTimeOriginal>File:FileCreateDate' `
    '-EXIF:CreateDate>File:FileCreateDate' `
  30. jtmoon79 revised this gist Jul 8, 2022. No changes.