Last active
February 10, 2023 18:38
-
-
Save mrkskwsnck/d5585d55c1647e3abef6fa640e0682f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Description: Rename argument files of taken photos (JPG) and videos (AVI) to a Nextcloud compatible timestamp format. | |
# | |
# Author: Markus Kwaśnicki | |
# | |
# Prerequisites: | |
# * { Install-Module -Name ExifDateTime -Scope CurrentUser } | |
# * { Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser } | |
# | |
# Setup: Create shortcut to | |
# `"C:\Program Files\PowerShell\7\pwsh.exe" -WindowStyle Hidden -File "%USERPROFILE%\Documents\PowerShell\Scripts\Rename-FotofallenFotos.ps1"´ inside | |
# `shell:SendTo´. | |
# | |
# Hint: Set `$DebugPreference = "Continue"´ for the debug messages to be displayed. | |
# | |
# See also: | |
# * https://github.com/ChrisWarwick/ExifDateTime | |
# * https://markw.dev/sendto_powershell/ | |
param ( | |
[Parameter(ValueFromRemainingArguments=$true)] | |
$FilePath | |
) | |
Get-ChildItem -Recurse -Path $FilePath | ForEach-Object { | |
if ((Split-Path $_ -Leaf) -match '^DSCF(\d{4}).*\.JPG') { | |
Get-ExifDateTaken $_ | ForEach-Object { | |
$NewName = '{0:yyyy-MM-dd HH-mm-ss} {1}.jpg' -f $_.ExifDateTaken, $Matches[1] | |
$RenameMessage = "Rename-Item from '{0}' to '{1}'" -f (Split-Path $_ -Leaf), $NewName | |
Write-Debug $RenameMessage | |
Rename-Item -Path $_ -NewName $NewName | |
} | |
} | |
} | |
Get-ChildItem -Recurse -Path $FilePath | ForEach-Object { | |
if ((Split-Path $_ -Leaf) -match '^DSCF(\d{4}).*\.AVI') { | |
$CreationTime = $_.CreationTime # Better this should be Exif date taken of the first (JPEG) frame | |
$NewName = '{0:yyyy-MM-dd HH-mm-ss} {1}.avi' -f $CreationTime, $Matches[1] | |
$RenameMessage = "Rename-Item from '{0}' to '{1}'" -f (Split-Path $_ -Leaf), $NewName | |
Write-Debug $RenameMessage | |
Rename-Item -Path $_ -NewName $NewName | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment