Having trouble setting a time zone offset during file renaming

Started by George Jardine, May 08, 2014, 06:48:16 PM

Previous topic - Next topic

George Jardine

Update: Tried both scripts on another (older) MacBook, and both scripts showed random, changed modification dates there too. I changed the cp line to use rsync, and now files copied from the card with rsync have preserved modification dates, on both laptops. But after the rsync copy, when I update the filenames using EXIFTool, I get random updated modification dates on one machine  (the newer, 2011 laptop) but not on the older 2008 laptop.

Phil Harvey

Hi George,

Back to the original topic...

I must be getting old.   I was reading the exiftool documentation (which I recommend to everyone), and discovered the -globalTimeShift feature that I had forgotten about.  This feature is designed with your workflow in mind.  So the clumsy 3-step process may be avoided, and this command will do what you want:

exiftool -r -P "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -globaltimeshift -6 -o "$DESTINATIONFOLDER" $CAMERACARDPATH

Sorry I didn't think of this earlier.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

helloguys

Quote from: Phil Harvey on May 18, 2014, 10:14:31 AM

exiftool -r -P "-FileName<DateTimeOriginal" -d "%Y%m%d-%H%M%S-%%f.%%e" -globaltimeshift -6 -o "$DESTINATIONFOLDER" $CAMERACARDPATH

- Phil

Phil,

This is very useful.  I must be greedy, but is there a way to do rename instead of copy?  I have tons of video files on a NAS.  Due to the size and number of files, the copy process is extremely slow.

I was thinking of using Windows scripting to rename the files if exiftool can extract the date/time from file and pass it to my script.

Phil Harvey

To move instead of copy, just don't use the -o option.  Instead, use -directory="DESTINATION FOLDER" to move the file, or write a full path to FileName.

But this will only help speed things up if both directories are on the same device.  It wouldn't help for the original intent of this thread, which it seems was to copy files from a camera's memory card.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

helloguys

Ok, I admit I'm a scripting newbie.  But I managed to build a Windows script (Rename.vbs) to do the job.

My scenario is: I have many MOV files from iPhone with the names of IMG_0001.MOV, IMG_0002.MOV, etc.  I wanted to rename them with the date/time of the video taken, in the format of "yyyy-mm-dd hh-mm-ss.mov" (e.g. "2015-06-13 10-30-25.mov").  I wanted to use local time instead of UTC (GMT time).

The workflow is very simple:
1) Get the file names in "./Media" folder (where all the MOV files are).
2) For each file, use "exiftool -ContentCreateDate" command to extract the creation date/time, which has the time in local time format.
3) Use the exiftool output to construct the filename I want.
4) Rename the file

Here's the file structure:

C:\Temp\exiftool.exe
C:\Temp\rename.vbs
C:\Temp\Media\IMG_0001.MOV
C:\Temp\Media\IMG_0002.MOV
...

To run the program, open a command prompt at "C:\Temp" and type "cscript rename.vbs".


Set objFSO = CreateObject("Scripting.FileSystemObject")

' .\Media is where I keep the *.MOV files
objStartFolder = ".\Media"

Set objFolder = objFSO.GetFolder(objStartFolder)

Set objShell = CreateObject("WScript.Shell")

Set colFiles = objFolder.Files

For Each objFile in colFiles
' Use exiftool to get the ContentCreateDate tag
Set objWshScriptExec = objShell.Exec("exiftool -ContentCreateDate " & objFile)
Set objStdOut = objWshScriptExec.StdOut
strOutput = objStdOut.ReadAll

strYear = mid(strOutput, 35, 4)
strMonth = mid(strOutput, 40, 2)
strDay = mid(strOutput, 43, 2)
strHour = mid(strOutput, 46, 2)
strMinute = mid(strOutput, 49, 2)
strSecond = mid(strOutput, 52, 2)

strNewName = strYear & "-" & strMonth & "-" & strDay & " " & strHour & "-" & strMinute & "-" & strSecond & ".mov"
strCmd = "%COMSPEC% /c ren " & objFile & " " & chr(34) & strNewName & chr(34)
objShell.Exec (strCmd)
Next

Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

helloguys

Thanks Phil for pointing this out.

Yes, the clumsy script can be replaced with a single command:

exiftool "-FileName<ContentCreateDate" -d "%Y-%m-%d %H-%M-%S%%-c.%%le" .\media

I guess the point is - if the media file has 'ContentCreateDate' tag available, that seems to be the best option to retrieve the local time.  Using "globalshift" might produce wrong time if media files are from different timezones.