How to Change File and Folder Date & Time Attributes Via the Command Line

When creating and modifying files and folders, Windows will use date and time stamps with these files and folders so you will know when they were made and also when they were changed.

Video - How to Change File and Folder Date & Time Attributes Via the Command Line

Watch video: How to Change File and Folder Date & Time Attributes Via the Command Line.

If you open a folder in File Explorer and view the files using the details view, you will be able to see the date modified folder by default. You can right click the column header and add the date created information if needed.

Windows File Explorer

You can also right click on a file or folder, choose Properties and see similar information.

File Properties

If you have any files or folders that you need to change the date and time attributes for, you can do so using the command line. The commands will vary depending on what you are trying to change.

In this article we will show you how to change the date created, date modified, and date accessed. We will also be showing you how to change date and time attributes for all the files in a specific folder.

In order to change file and folder date and time attributes via the command line, you will need to open PowerShell as an administrator so be sure your account has admin access, or you know the credentials of one that does. The easiest way to do this is to do a search for PowerShell and then choose the Run as Administrator option.

Run PowerShell as Administrator

For our first example, we will change the date created for the file called Brochure.docx. To do so, we will run the following command.

Syntax

(Get-Item “PathToItem”).CreationTime=(“15 January 2024 10:00:00”)

Command Example

(Get-Item “C:\Users\todds\Desktop\Files\Brochure.docx”).CreationTime=(“15 January 2024 10:00:00”)

This will change the created date of the file to January 15th 2024 at 10:00 AM.

As you can see, you will not be shown any message indicating it was successful after running the command.

How to Change File and Folder Date & Time Attributes Via the Command Line

Now when we go back to the folder and view the file, we can see that the date and time attributes have been changed to match what was in the command for the date created attribute.

How to Change File and Folder Date & Time Attributes Via the Command Line

For our next example, we will be changing the date modified attribute for the file called Cybersecurity Awareness.pdf.

Syntax

(Get-Item “PathToItem”).LastWriteTime=(“16 January 2022 11:00:00”)

Command Example

(Get-Item “C:\Users\todds\Desktop\Files\Cybersecurity Awareness.pdf “).LastWriteTime=(“16 January 2024 11:00:00”)

This will change the modified date of the file to January 16th 2024 at 11:00 AM as seen in the image below.

How to Change File and Folder Date & Time Attributes Via the Command Line

Next, we sill change the date accessed time for the file named Fax Cover Sheet.docx.

Syntax

(Get-Item “PathToItem”).LastAccessTime=(“17 January 2022 12:00:00”)

Command Example

(Get-Item “C:\Users\todds\Desktop\Files\Fax Cover Sheet.docx”).LastAccessTime=(“17 January 2024 12:00:00”)

This will change the last accessed date of the file to January 17th 2024 at 12:00 PM as seen in the image below after enabling the Date accessed column.

How to Change File and Folder Date & Time Attributes Via the Command Line

If for some reason the date accessed does not change, you can try running the following command and then retry the previous step.

fsutil behavior set disablelastaccess 0

For our final example, we will be changing the creation time for all of the files in a folder. The text below shows the commands used to change the creation time, modified time and accessed time.

Get-ChildItem -force PathToItem * | ForEach-Object{$_.CreationTime = (“15 January 2024 10:00:00”)}

Get-ChildItem -force PathToItem * | ForEach-Object{$_.LastWriteTime = (“15 January 2024 10:00:00”)}

Get-ChildItem -force PathToItem * | ForEach-Object{$_.LastAccessTime = (“15 January 2024 10:00:00”)}

 

Command Example

Get-ChildItem -force C:\Users\todds\Desktop\Files * | ForEach-Object{$_.CreationTime = (“30 March 2024 10:00:00” )}

This will change the date created for all the files in the folder to March 30th, 2024 at 10:00 AM.

How to Change File and Folder Date & Time Attributes Via the Command Line

As you can see, its not too difficult to change the file and folder date & time attributes via the command line once you get the proper syntax figured out.

For additional training resources, check out our online training courses.

Related Posts

© 2024 Online Computer Tips
Website by Anvil Zephyr