Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows Can';t get Folder.GetDetailsOf()以秒为单位返回文件时间_Windows_File_Powershell_Time - Fatal编程技术网

Windows Can';t get Folder.GetDetailsOf()以秒为单位返回文件时间

Windows Can';t get Folder.GetDetailsOf()以秒为单位返回文件时间,windows,file,powershell,time,Windows,File,Powershell,Time,当我的iPhone连接到我的Windows笔记本电脑时,我正在尝试从iPhone上的文件访问文件创建的时间信息。我已经编写了一个小的PowerShell测试脚本,它成功地实现了这一点,但有一个小缺点:返回文件创建时间的函数不包括秒…(示例输出为“18/03/2017 21:58”。) 如何使Folder.GetDetailsOf()也返回秒数 我尝试应用不同的文化(区域设置): 使用所需的时间格式设置新的区域性 使用区域性包装所有内容,如上所述 将系统范围的短时格式(在Windows设置中=>

当我的iPhone连接到我的Windows笔记本电脑时,我正在尝试从iPhone上的文件访问文件创建的时间信息。我已经编写了一个小的PowerShell测试脚本,它成功地实现了这一点,但有一个小缺点:返回文件创建时间的函数不包括秒…(示例输出为“18/03/2017 21:58”。)

如何使Folder.GetDetailsOf()也返回秒数

我尝试应用不同的文化(区域设置):

  • 使用所需的时间格式设置新的区域性
  • 使用区域性包装所有内容,如上所述
  • 将系统范围的短时格式(在Windows设置中=>时钟、语言和区域)设置为“HH:mm:ss”
所有这些似乎都不起作用……然而,该功能很好地应用了新的文化。这两个函数之间的主要区别在于Folder.GetDetailsOf通过COM对象(Shell.Application)运行,而Get Date则不通过。如果使用不同的区域性确实是一种方法,那么如何将它们应用于COM对象

示例脚本 为什么我需要这个? 当从我的iPhone上复制视频时,这些文件在我的笔记本电脑上获得了一个新的创建时间,因此我失去了原始(实际)时间。修改后的时间确实会被复制,但并不总是正确的。(不太清楚为什么,有时在我拍摄完视频后不处理视频时也会发生这种情况。)

为了修复创建的时间,我希望在视频还在手机上的时候从视频中提取创建的时间,这样我就可以将它们写入一个文件,稍后再获取它们


当然,对于如何解决此问题的任何其他建议也欢迎:)

标题是关于从文件夹中获取秒数,但文本是关于将PowerShell区域设置应用于COM对象。请确定您的问题是什么,并使标题与文本匹配。有点晚了,所以您可能不再需要这个了,但我只是偶然发现了这个问题,所以我将回答我的一个问题,“为下一代”,因为它显示了如何使用VBA中的FSO检索文件夹或文件,时间缩短到毫秒(很容易适应VBS)标题是关于从文件夹中获取秒数,但文本是关于将PowerShell区域设置应用于COM对象。请确定您的问题是什么,并使标题与文本匹配。有点晚了,所以您可能不再需要这个了,但我只是偶然发现了这个问题,所以我将回答我的一个问题,“为下一代”,因为它显示了如何使用VBA中的FSO检索文件夹或文件,时间缩短到毫秒(很容易适应VBS)
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)
}