I'm trying to access file created time information from files on my iPhone, when it's connected to my Windows laptop. I've put together a small PowerShell test script that succesfully does so, with one small shortcoming: the function Folder.GetDetailsOf(..., 4), which returns the file's created time, does not include seconds… (An example output would be "18/03/2017 21:58".)
How would I get Folder.GetDetailsOf() to return seconds also?
I've tried applying a different culture (locale):
- Setting a new culture using the required time format;
- Wrapping everything in Using-Culture, as described on the MSDN blog;
- Setting the system-wide short time format (in Windows Settings => Clock, Language, and Region) to "HH:mm:ss".
None of this seems to work… However, the function Get-Date applies the new culture just fine. The main difference between these two functions, is that Folder.GetDetailsOf runs via a COM object (Shell.Application), whereas Get-Date does not. If using a different culture is indeed the way to go, then how could I apply them to COM objects?
Example script
Function Using-Culture (
[System.Globalization.CultureInfo]$culture = (throw “USAGE: Using-Culture -Culture culture -Script {scriptblock}”),
[ScriptBlock]$script= (throw “USAGE: Using-Culture -Culture culture -Script {scriptblock}”)
) {
$OldCulture = [System.Threading.Thread]::CurrentThread.CurrentCulture
trap {
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
[System.Threading.Thread]::CurrentThread.CurrentCulture = $culture
Invoke-Command $script
[System.Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
}
$currentThread = [System.Threading.Thread]::CurrentThread
[System.Globalization.CultureInfo] $culture = "nl-NL"
$culture.DateTimeFormat.LongTimePattern = 'HH:mm:ss'
$culture.DateTimeFormat.ShortTimePattern = 'HH:mm:ss'
$culture.DateTimeFormat.FullDateTimePattern = 'dd MMMM, yyyy HH:mm:ss'
$currentThread.CurrentCulture = $culture
$currentThread.CurrentUICulture = $culture
Using-Culture $culture {
# This outputs the date in Dutch, using the format above;
# if the format above is changed, then Get-Date's output does too
Get-Date
$path = 'C:\Windows\System32\notepad.exe'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)
# GetDetailsOf() on the other hand is oblivious to the newly set culture
$shellfolder.GetDetailsOf($shellfile, 4)
}
Why do I need this?
When copying videos off my iPhone, the files get a new Created time on my laptop, so I lose the original (actual) time. The Modified time does get copied, but it's not always correct. (Not quite sure why, this sometimes also happens when I don't do anything with the video after having shot it.)
In order to fix the Created time, I'm looking to extract the Created time from the videos while they're still on the phone, so I can write them to a file, and fetch them again later.
Any other suggestions on how to tackle this problem are of course also welcome :)