PowerTip of the Day-Changing File/Folder Creation Date

原文地址: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这样的日期在系统里会显示为空,换成比较近的日期就正常。

 

posted @ 2010-06-08 10:39  哥本哈士奇(aspnetx)  阅读(396)  评论(0编辑  收藏  举报