zoukankan      html  css  js  c++  java
  • PowerTip of the DayChanging 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这样的日期在系统里会显示为空,换成比较近的日期就正常。

  • 相关阅读:
    寒假13
    寒假作业十二
    寒假12
    寒假作业十一
    寒假11
    寒假作业九
    寒假10
    寒假作业九
    寒假9
    寒假作业八
  • 原文地址:https://www.cnblogs.com/aspnetx/p/1753788.html
Copyright © 2011-2022 走看看