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.
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.
DateTime newCreate = new DateTime(year, month, day, hour, minutes, seconds); File. SetCreationTime("changemydate. txt", newCreate);
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
.
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")
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With