Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I programmatically change the create, modify, access date on a file?

I need to change the modify date on a file on Windows so that it doesn't clutter up my sort order. How can I do that with a script (I may need to do that to the file in the future as well)?

BTW: I don't want to have to install applications to do this.

like image 319
Keng Avatar asked Feb 24 '09 16:02

Keng


People also ask

How can I change the last modified date of a file in Java?

Use the parse(String) method of the SimpleDateFormat class to create a new Date object with the date value of the String we created. Finally, use File. setLastModified(Date. getTime()) method to set the new “Last Modified” date of our file.

How can I change the modified date of a file in C#?

DateTime newCreate = new DateTime(year, month, day, hour, minutes, seconds); File. SetCreationTime("changemydate. txt", newCreate);


3 Answers

If you have PowerShell:

$(Get-Item ).creationtime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")
$(Get-Item ).lastaccesstime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")
$(Get-Item ).lastwritetime=$(Get-Date "mm/dd/yyyy hh:mm am/pm")

Note that the correct date format string to use will depend on your localization, e.g. in the UK, the correct format string would be dd/mm/yyyy.

like image 136
Learning Avatar answered Sep 30 '22 05:09

Learning


Using PowerShell, the command would be:

PS C:\temp> (Get-Item Notes.txt).lastwritetime=$(Get-Date "1/2/2016 12:34 am")

PS C:\temp> (Get-Item Notes.txt).creationtime=$(Get-Date "1/2/2016 12:34 am")

PS C:\temp> (Get-Item Notes.txt).lastaccesstime=$(Get-Date "1/2/2016 12:34 am")

Enter image description here

like image 34
Mark G Avatar answered Sep 30 '22 03:09

Mark G


Here is a VBScript example of changing the modification date:

Sub ChangeModifiedDate(strFolder, strFile, dteNew)

    Dim oShell
    Dim objFolder

    Set oShell = CreateObject("Shell.Application")
    Set oFolder = oShell.NameSpace(strFolder)
    oFolder.Items.Item(strFile).ModifyDate = dteNew
End Sub
like image 26
EBGreen Avatar answered Sep 30 '22 04:09

EBGreen