我想通过在ASP Classic上调用SetFileTime或类似的东西来手动更改指定时间的日期和时间。据我所知,ASP File Object提供了检索创建的方法。文件的修改时间,但没有提供实际设置它们的方法。
我怎样才能做到这一点?
答案 0 :(得分:0)
我找到的答案相对较快:
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
然后你只需通过
调用例行程序 Call ModifyLastAccessedDate("C:\Folder\SomeFile.Txt","2013-03-05")
答案 1 :(得分:0)
以下是JScript中的一个示例,同样在VB中,直接从Microsoft直接用于后代(以及如何设置日期和时间字符串的另一个示例):
<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