1

I'd like to manually change the date and time for a specified time by invoking SetFileTime or something similar but on ASP Classic. As far as I know, ASP File Object provides method for retrieving the creation & modification times for the file but provides no methods for actually setting them.

How can I achieve this?

4

2 回答 2

0

I found the answer relatively quickly:

Sub ModifyLastAccessedDate(emlFilePath, newDate)
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set file = objFSO.GetFile(emlFilePath)
    Set app = Server.CreateObject("Shell.Application") 
    Set folder = app.NameSpace(file.ParentFolder & "\") 
    Set fileModify = folder.ParseName(file.Name) 

    fileModify.ModifyDate = NewDate 

    Set objFSO = Nothing
    Set file = Nothing 
    Set folder = Nothing 
    Set app = Nothing 
    Set fileModify = Nothing
End Sub

And then you just call the routine by

Call ModifyLastAccessedDate("C:\Folder\SomeFile.Txt","2013-03-05")

于 2013-03-04T08:19:49.150 回答
0

Here is an example in JScript, and again in VB, taken directly from Microsoft just for posterity (and as another example of how the date and time string can be set):

<script language="JScript">
    function fnModifyDateGetSetJ()
    {
        var objShell = new ActiveXObject("shell.application");
        var objFolder2;
        var ssfWINDOWS = 36;

        objFolder2 = objShell.NameSpace(ssfWINDOWS);
        if (objFolder2 != null)
        {
            var objFolderItem;

            objFolderItem = objFolder2.ParseName("NOTEPAD.EXE");
            if (objFolderItem != null)
            {
                var szReturn;

                szReturn = objFolderItem.ModifyDate;
                objFolderItem.ModifyDate = "01/01/1900 6:05:00 PM";
            }
        }
    }
</script>

VB:

Private Sub fnModifyDateGetSetVB()
    Dim objShell   As Shell
    Dim objFolder2 As Folder2
    Dim ssfWINDOWS As Long

    ssfWINDOWS = 36
    Set objShell = New Shell
    Set objFolder2 = objShell.NameSpace(ssfWINDOWS)
        If (Not objFolder2 Is Nothing) Then
            Dim objFolderItem As FolderItem

            Set objFolderItem = objFolder2.ParseName("NOTEPAD.EXE")
                If (Not objFolderItem Is Nothing) Then
                    Dim szReturn As String

                    szReturn = objFolderItem.ModifyDate
                    objFolderItem.ModifyDate = "01/01/1900 6:05:00 PM"
                Else
                    'FolderItem object returned nothing.
                End If
            Set objFolderItem = Nothing
        Else
            'Folder object returned nothing.
        End If
    Set objFolder2 = Nothing
    Set objShell = Nothing
End Sub
于 2016-06-29T08:03:30.573 回答