Seach Files for latest file

Seach Files for latest file

am 12.11.2007 01:33:06 von MM User

Hi,

I have a directory which I would like to search and list the latest file
together with it date and time, I've found the following from w3schools for
a particular file but do not know how to search a folder and sub folders for
the latest 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


Any help is appreciated!

Re: Seach Files for latest file

am 12.11.2007 05:41:53 von McKirahan

"MM User" wrote in message
news:upYeeOMJIHA.4688@TK2MSFTNGP06.phx.gbl...
> Hi,
>
> I have a directory which I would like to search and list the latest file
> together with it date and time, I've found the following from w3schools
for
> a particular file but do not know how to search a folder and sub folders
for
> the latest 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

Will this help? Watch for word-wrap.

<%@ Language="VBScript" %>
<% Option Explicit
'*
'* Declare Constants
'*
Const cFOL = "D:\Temp"
'*
'* Declare Variables
'*
Dim i,j,k
Dim strDLM
Dim arrFIL()
Dim intFIL
intFIL = 0
Dim strFIL
Dim strFOL
Dim strNAM
Dim arrNEW
Dim strNEW
strNEW = "?"
Dim dtmNOW
dtmNOW = Now
Dim intSEC
Dim strSEC
'*
'* Declare Objects
'*
Dim objFSO
Dim objGFI
'*
'* GetFiles()
'*
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(cFOL) Then
Call GetFiles(cFOL)
'*
'* Sort Files
'*
For i = UBound(arrFIL) - 1 To 0 Step -1
For j = 0 To i
If arrFIL(j) > arrFIL(j+1) Then
k = arrFIL(j+1)
arrFIL(j+1) = arrFIL(j)
arrFIL(j) = k
End If
Next
Next
'*
'* Newest File
'*
arrNEW = Split(arrFIL(0),"^")
strNEW = arrNEW(1) & " : " & arrNEW(2)
End If
Set objFSO = Nothing
'*
'* Newset File
'*
Response.Write strNEW

Sub GetFiles(folder)
'*
'* Get Files in folder
'*
For Each strFIL In objFSO.GetFolder(folder).Files
Set objGFI = objFSO.GetFile(folder & "\" & strFIL.Name)
strDLM = objGFI.DateLastModified
intSEC = DateDiff("s",strDLM,dtmNOW)
strSEC = 10^10+intSEC
Set objGFI = Nothing
strNAM = folder & "\" & strFIL.Name
ReDim Preserve arrFIL(intFIL)
arrFIL(intFIL) = strSEC & "^" & strNAM & "^" & strDLM
intFIL = intFIL + 1
Next
'*
'* Get Subfolders
'*
For Each strFOL In objFSO.GetFolder(folder).SubFolders
Call GetFiles(strFOL.Path)
Next
End Sub
%>