Change file times

When a file is created, accessed or modified that time is recorded. This is how to change file times.

There are three properties to consider:

CreationTime

LastAccessTime

LastWriteTime

Just to add to the fun there are UTC (GMT in real world) times as well:

CreationTimeUtc

LastAccessTimeUtc

LastWriteTimeUtc

If you need to change a property its a set operation. For instance

Get-ChildItem -Path x9.txt | foreach {$_.LastWriteTime = ($_.LastWriteTime).AddHours(6)}

Substitute the appropriate property as required. If you change a property the UTC version is changed in step – accounting for timezone differences

Advertisements
This entry was posted in Powershell. Bookmark the permalink.

One Response to Change file times

  1. Luke says:

    Not sure I will some day change thoses values because they are automatically managed by the system.
    However, it’s an interesting concrete exercise about handling objects.
    Thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s