原文地址:http://app.en25.com/e/es.aspx?s=1403&e=4273&elq=1cbc05ed0b11413db47a3b65bc2ee7a4

原文:

 

Changing File/Folder Creation Date

You should use this approach if you need to change the creation time of a folder or file after you have created it:

Get-Childitem c:\testfolder | Foreach-Object { $_.CreationTime = '1/1/1972 10:35'

It will change creation time of c:\testfolder to the date and time specified. Note that the date-time format used here needs to match your local date-time format. A more general approach would be to use Get-Date with its parameters to construct a culture-neutral date and assign that to the file/folder CreationDate property.

 

翻译:

更改文件或者文件夹的创建时间

使用以下的方法可以更改已经建立好的文件或者文件夹的创建时间。

Get-Childitem c:\testfolder | Foreach-Object { $_.CreationTime = '1/1/1972 10:35'}

这段代码会更改c:\testfolder的创建时间为一个指定的时间。需要注意的是时间格式必须跟本地机器的时间格式相符。通常的做法是用Get-Date加适当的参数来构建一个日期并且把它赋给文件或者文件夹的创建日期属性里。

 

笔记:

原文代码有处问题,foreach后面少一个}结束标记。

原文代码的逻辑是改一个指定文件夹下的所有元素的创建日期,所以标题似乎不太妥当。不过其意思已经表达的很清楚了。

复习以下cmdlet用法:get-childitem(奇怪为什么不是get-childrenitems)foreach-object(不是foreach,更明了)

测试发现1972这样的日期在系统里会显示为空,换成比较近的日期就正常。

 

相关文章:

  • 2022-02-09
  • 2022-01-21
  • 2021-11-14
  • 2021-09-22
  • 2021-10-11
  • 2021-09-26
  • 2021-08-19
  • 2022-02-02
猜你喜欢
  • 2021-06-09
  • 2021-12-01
  • 2021-12-12
  • 2022-01-16
  • 2021-07-08
  • 2022-02-22
  • 2021-12-03
相关资源
相似解决方案