ASP DateLastModified 属性
定义和用法
DateLastModified 属性用于返回指定的文件或文件夹最后被修改的日期和时间。
语法:
FileObject.DateLastModified
FolderObject.DateLastModified
针对 File 对象的例子
<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
set f=fs.GetFile("c:\test.txt")
Response.Write("File last modified on: ")
Response.Write(f.DateLastModified
)
set f=nothing
set fs=nothing
%>
输出:
File last modified on: 8/8/2008 8:8:00 PM
演示代码程序(www.fly810.com):Option Explicit
Private Type typFlieDate
Name As String
CreatedDate As Date
AccessedDate As Date
ModifiedDate As Date
End Type
Private myFiles() As typFlieDate '包含文件的数组
Private Sub Command1_Click()
Dim n As Integer
n = GetFolderFiles( "d:\" , 1)
End Sub
Private Function GetFolderFiles(Path As String, OrderBy As Integer) As Integer
'path 文件夹路径 (www.fly810.com)
'orderby 排序依据 1:按创建时间 2:按访问时间 3:按修改时间 4:按名称
'返回文件夹中文件的个数
'如果要计算子文件夹可以通过 fldr.SubFolders 访问,方法类似
Dim tmpFile As typFlieDate
Dim n As Integer, i As Integer, j As Integer
Dim fso As New FileSystemObject
Dim fldr As Folder
Dim fls As Files
Dim fl As File
'读去文件
Set fso = CreateObject("Scripting.FileSystemObject")
Set fldr = fso.GetFolder(Path)
Set fls = fldr.Files
n = fls.Count
If n > 0 Then
ReDim myFiles(n - 1)
i = 0
For Each fl In fls
myFiles(i).Name = fl.Name
myFiles(i).AccessedDate = fl.DateLastAccessed
myFiles(i).CreatedDate = fl.DateCreated
myFiles(i).ModifiedDate = fl.DateLastModified
i = i + 1
Next
'排序 --- 升序
For i = 0 To n - 1
For j = i + 1 To n - 1
Select Case OrderBy
Case 1 '创建时间 (www.fly810.com)
If myFiles(i).CreatedDate > myFiles(j).CreatedDate Then
tmpFile = myFiles(i)
myFiles(i) = myFiles(j)
myFiles(j) = tmpFile
' tmpFile.Name = myFiles(i).Name
' tmpFile.AccessedDate = myFiles(i).AccessedDate
' tmpFile.CreatedDate = myFiles(i).CreatedDate
' tmpFile.ModifiedDate = myFiles(i).ModifiedDate
'
' myFiles(i).AccessedDate = myFiles(j).AccessedDate
' myFiles(i).CreatedDate = myFiles(j).CreatedDate
' myFiles(i).ModifiedDate = myFiles(j).ModifiedDate
' myFiles(i).Name = myFiles(j).Name
'
' myFiles(j).AccessedDate = tmpFile.AccessedDate
' myFiles(j).CreatedDate = tmpFile.CreatedDate
' myFiles(j).ModifiedDate = tmpFile.ModifiedDate
' myFiles(j).Name = tmpFile.Name
End IfCase 2 '访问时间
If myFiles(i).AccessedDate > myFiles(j).AccessedDate Then
tmpFile = myFiles(i)
myFiles(i) = myFiles(j)
myFiles(j) = tmpFile
End If
Case 3 '修改时间
If myFiles(i).ModifiedDate > myFiles(j).ModifiedDate Then
tmpFile = myFiles(i)
myFiles(i) = myFiles(j)
myFiles(j) = tmpFile
End If
Case 4 '名称
If UCase(myFiles(i).Name) > UCase(myFiles(j).Name) Then
tmpFile = myFiles(i)
myFiles(i) = myFiles(j)
myFiles(j) = tmpFile
End If
End Select
Next j
Next i
End If
GetFolderFiles = n
End Function