The DateLastModified property of the FileSystemObject is read-only. However, you can use Shell.Application to achieve this (thanks for the tip, Richard):
<% Sub Touch(FolderPath, FileName, NewDate) Set app = CreateObject("Shell.Application") Set folder = app.NameSpace(FolderPath) Set file = folder.ParseName(FileName) file.ModifyDate = NewDate set file = nothing set folder = nothing set app = nothing End Sub Call Touch(Server.MapPath("/"), "somefile.htm", "2005-09-01") Call Touch("C:\", "somefile.txt", "2012-01-01") %> |
I was unable to get this to work on my local system, but I have been assured by others that this will work.
If it's a text-based file, you could read in the contents of the file, delete the file, and re-create it. That would alter the create *and* modify time of the file, and might not be the desired result (especially since you can't just pass in an arbitrary date/time). Here is the code to do this in VBScript:
<% Sub Touch(FolderPath, FileName) set fso = CreateObject("Scripting.FileSystemObject") set fs = fso.openTextFile FolderPath & FileName, 1, true f = fs.readAll() fs.close: set fs = nothing fso.deleteFile FolderPath & FileName, true set fs = fso.createTextFile FolderPath & FileName, true fs.writeline(f) fs.close: set fs = nothing Set fso = nothing End Sub Call Touch(Server.MapPath("/"), "somefile.htm") Call Touch("c:\", "somefile.txt") %> |
As a last resort, you could use Touch.EXE (from the Resource Kit), called via Shell.Application...