Searching file system and returning xml based on date search crite

B

Bryan

Hello group.
I've migrated from Win 2003 server to Win 2008 server.
I've been banging my head agaist a wall for several days now trying to
figure this out.

I have the following script that will search the file system and return file
names of all files within a folder and subfolders that meet the search
criteria of DateLastModified.

To test the output, you can use the following link:
http://www.hurricanealley.net/GT/ne...008 4:00 PM
or even change the date time input in the URL.
The input part of the url is the date and time.
To see the actual file dates you can look here:
http://www.hurricanealley.net/GT/Data (sub folders also)

The problem I'm having is that some files names/paths that are returned are
older than the search criteria date/time and some files that are newer are
not being returned.
Any suggestions would be greatly appreciated
--
<%@ Language=VBScript %>
<?xml version="1.0" encoding="iso-8859-1"?>
<%

' Init path parameters
start_path = "data"
start_url = ""

' Parse date param
s = ""
for i = 1 to len(Request.QueryString)
if mid(Request.QueryString, i, 3) = "%20" then s = s + " " : i = i + 2
else s = s + mid(Request.QueryString, i, 1)
next
dim sdate
dim stime
n = 0 : sdate = s : stime = ""
for i = 1 to len(s) - 1
if mid(s, i, 1) = " " and n = 0 then n = i
next
if n > 0 then sdate = Trim(Left(s, n - 1)) : stime = Trim(Right(s, Len(s) -
n))

Dim RequestDateTime
RequestDateTime = DateValue(sdate)
if stime <> "" then RequestDateTime = RequestDateTime + TimeValue(stime)

' Write root node
%><newfiles fromdate="<%= s %>" datestr="<%= sdate %>" timestr="<%= stime
%>" resultdatetime="<%= RequestDateTime %>">
<%

' Create FileSystemObject variable
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

' Process specified folder
tmp = ProcessFolder(Server.MapPath(start_path), start_url, chr(9), 0)

Set objFSO = Nothing


'---------------------------------------------


' Write file xml-node
Function WriteFile(objItem, strUrl, space)
%><%=space%><file name="<%= objItem.Name %>" size="<%= objItem.Size %>"
date="<%= objItem.DateCreated %>" url="<%= strUrl & objItem.Name %>"/>
<%
End Function

' Process folder
' writemode: 0 - write to xml-page, 1 - return new items count, 2 - return
newitems size
Function ProcessFolder(strPath, strUrl, space, writemode)

Dim objFolder 'Folder variable
Dim objItem 'Variable used to loop through the contents of the folder

' Get a handle on our folder
Set objFolder = objFSO.GetFolder(strPath)

res = 0

'scan files
For Each objItem In objFolder.Files
If (objItem.DateLastModified > RequestDateTime) or (objItem.Name =
"ImageMap.xml") Then
If writemode = 0 Then tmp = WriteFile(objItem, strUrl, space)
If writemode = 1 Then res = res + 1
If writemode = 2 Then res = res + objItem.Size
End If
Next 'objItem

'scan subfolders
For Each objItem In objFolder.SubFolders
If InStr(1, objItem, "_vti", 1) = 0 Then
new_path = strPath & "\" & objItem.Name
lchar = "/" : if len(strUrl) > 0 then lchar = right(strUrl, 1)
new_url = strUrl & objItem.Name & "/"
If writemode = 0 Then
' calc newitems count and size
items_count = ProcessFolder(new_path, "", "", 1) 'calc count
items_size = ProcessFolder(new_path, "", "", 2) 'calc size
' write folder xml-node
%><%=space%><folder name="<%= objItem.Name %>" newitems="<%=items_count%>"
newitems_size="<%=items_size%>">
<%
tmp = ProcessFolder(new_path, new_url, space + chr(9), writemode)
%><%=space%></folder>
<%
End If
If writemode >= 1 Then
res = res + ProcessFolder(new_path, "", "", writemode)
End If
End If
Next 'objItem

' All done! Kill off our object variables.
Set objItem = Nothing
Set objFolder = Nothing

ProcessFolder = res

End Function

%>
</newfiles
--------------------------------------------------------------------------------



Thanks!
Bryan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top