Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.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
File 文件副本上的PowerShell脚本集创建日期失败_File_Powershell - Fatal编程技术网

File 文件副本上的PowerShell脚本集创建日期失败

File 文件副本上的PowerShell脚本集创建日期失败,file,powershell,File,Powershell,我编写了一个简单的PowerShell脚本,通过允许我妻子手动指定正确的创建日期来帮助她组织一些导入的iPhone视频文件。它似乎像预期的那样工作,只是如果我复制了其中一个文件,就无法设置副本的创建日期 注:在这种情况下,一天中的时间可以忽略不计 $movFiles = Get-ChildItem "C:\Users\jgrant\Desktop\videos" -Filter *.MOV Foreach ($file in $movFiles) { $fileName = $file.

我编写了一个简单的PowerShell脚本,通过允许我妻子手动指定正确的创建日期来帮助她组织一些导入的iPhone视频文件。它似乎像预期的那样工作,只是如果我复制了其中一个文件,就无法设置副本的创建日期

注:在这种情况下,一天中的时间可以忽略不计

$movFiles = Get-ChildItem "C:\Users\jgrant\Desktop\videos" -Filter *.MOV
Foreach ($file in $movFiles) {
    $fileName = $file.Name
    $userDate = Read-Host -Prompt "Date wanted for ${fileName} (format--> 1970-02-13) "
    $newDateObj = Get-Date -Date $userDate
    $item.CreationTime = $newDateObj
}

验证结果时,所有文件都已正确修改,但我刚刚复制的文件除外。有没有办法强制修改创建日期(除了在复制前更改日期)?具体来说,是什么机制阻碍了我?

正如autosvet在他们的评论中指出的那样,我只是在变量名中犯了一个错误。更正是将变量$item更改为$file。以下是正确的代码:

$movFiles = Get-ChildItem "C:\Users\jgrant\Desktop\videos" -Filter *.MOV
Foreach ($file in $movFiles) {
    $fileName = $file.Name
    $userDate = Read-Host -Prompt "Date wanted for ${fileName} (format--> 1970-02-13) "
    $newDateObj = Get-Date -Date $userDate
    $file.CreationTime = $newDateObj
}

再次感谢autosvet。

您应该使用$file.CreationTime而不是$item.CreationTime,它就在这里。谢谢。简单一点:)你想把它作为答案重新发布吗?