FileTimeSet but for Directories

Started by User_McUser, February 12, 2024, 12:11:55 PM

Previous topic - Next topic

User_McUser

Is there a function that is the equivalent of FileTimeSet but for directories instead of files?

Doesn't seem like there is but thought I'd ask to be sure.

Thanks! 👍

td

You can try the following.

Code (winbatch) Select
; Date to set
Date = ObjectClrNew("System.DateTime", 2001, 1, 1, 8, 0, 15)

; Set the date on the target directory
Dir = ObjectClrNew("System.IO.Directory")
Dir.SetCreationTime("C:\Temp\Trash", Date)

; Make sure that no process is using the directory.
; This includes Windows File Explorer not having a
; window open to it.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

User_McUser

I actually need to change the Last Modified date on the directory - but with your example I was able to find the Microsoft Directory Class documentation online and used the "SetLastWriteTime" method in place of "SetCreationTime" and it works perfectly.  :D

Thank you!

Code (winbatch) Select

Date = ObjectClrNew("System.DateTime", 1999,2,14,9,38,26)

Dir = ObjectClrNew("System.IO.Directory")
Dir.SetLastWriteTime("C:\temp", Date)

td

Great. You took the initiative and found the solution that best fits your needs.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade