Anthony, Thanks for the sample code... I'll try it out.. The code is used by another compiled program to download files from a web server. Basically all files that are newer than the cutoff date are returned in the xml, then another program downloads the files. I don't have any control over the other program, so the xml has to look/function like the existing xml to work. Thanks again! -- Thanks! Bryan
"Anthony Jones" wrote:
"Bryan" <Bryan@discussions.microsoft.com> wrote in message news:8DBAF0A9-D4C7-4C4A-B850-15AC5A638503@microsoft.com... I have some code (given to me), but I don't know alot about ASP, so I was hoping someone here can help. Running on Win 2008 server. The code below will scan a folder and subfolder with a date/time input and return xml structure off all files that are newer than the supplied date/time. The problem is that the returned xml has path names like C:\folder\subfolder\filename.ext I would like it to be more like /folder/subfolder/filename.ext Also, the initial path gets returned in the xml "data", but I only want the sub folders below "data" to get scanned and info returned... Any help would be greatly appreciated. function indent(iTreeLevel) '========================================== function newItemsCount(objFolder, dCutoffDate) For Each objFile In objFolder.Files sFileModified = objFile.DateLastModified If (sFileModified > dCutoffDate) Then '========================================== function newItemsSize(objFolder, dCutoffDate) For Each objFile In objFolder.Files sFileModified = objFile.DateLastModified If (sFileModified > dCutoffDate) Then '========================================== sub FolderListing(strPath, dCutoffDate, blnRecursive, iTreeLevel) Set objFolder = objFSO.GetFolder(strPath) response.write(inde nt(iTreeLevel) & "<folder name=""" & objFolder.Name & """ newitems=""" & newItemsCount(objFolder, dCutoffDate) & """ newitems_size=""" & newItemsSize(objFolder, dCutoffDate) & """>" & vbCrLf) For Each objFile In objFolder.Files sFileCreated = objFile.DateCreated sFileModified = objFile.DateLastModified If (sFileModified > dCutoffDate) Then response.write(indent(iTreeLevel) & " <file name=""" & sFileName & """ size=""" & sFileSize & """ date=""" & sFileModified & """ url=""" & strPath & "\" & sFileName & """/>" & vbCrLf) Set objSubFolders = objFolder.SubFolders For Each objFolder in objSubFolders sFolderPath = strPath & "\" & sFolderName FolderListing sFolderPath, dCutoffDate, blnRecursive, iTreeLevel+1 response.write(indent(iTreeLevel) & "</folder>" & vbCrLf) '=========================================================================== ============== sDateTime = unescape(Request.QueryString) aDateTime = split(sDateTime, " ") sTime = aDateTime(1) & " " & aDateTime(2) dDateTime = dDate + dTime Set objFSO = Server.CreateObject("Scripting.FileSystemObject") <?xml version="1.0" encoding="utf-8"?> <newfiles fromdate="<%= dDate %>" datestr="<%= sDate %>" timestr="<%= sTime %>" resultdatetime="<%= dDateTime %>"> FolderListing server.MapPath("data"), dDateTime, true, 0 Could not bring myself to tweak that code. Here is an alternative ASP:- <% Dim gfso : Set gfso = Server.CreateObject("Scripting.FileSystemObject") Dim gdatCutOff : gdatCutOff = FromISO8601(Request.QueryString("cutoff")) Dim goXML : Set goXML = Server.CreateObject("MSXML2.DOMDocument.6.0") goXML.LoadXML "<newItems />" Dim gelemNewFiles : Set gelemNewFiles = goXML.documentElement gelemNewFiles.setAttribute "from", ToISO8601(gdatCutOff) Dim goDataFolder : Set goDataFolder = gfso.GetFolder(Server.MapPath("data")) GetFolderXML gelemNewFiles, goDataFolder, gdatCutOff DropElems gelemNewFiles, "folder[@name='data']/file" Response.ContentType = "text/xml" Response.CharSet = "UTF-8" goXML.Save Response Sub GetFolderXML(relemParent, roFolder, rdatCutOff) Dim oFolder Dim oFile Dim elemFolder Dim elemFile Set elemFolder = AddElem(relemParent, "folder", Null) For Each oFolder In roFolder.SubFolders GetFolderXML elemFolder, oFolder, rdatCutOff Next For Each oFile In roFolder.Files If oFile.DateLastModified > rdatCutOff Then Set elemFile = AddElem(elemFolder, "file", Null) elemFile.setAttribute "size", oFile.Size elemFile.setAttribute "lastModified", ToISO8601(oFile.DateLastModified) End If Next End Sub Sub DropElems(relem, rsXPath) Dim oNode Dim oList : Set oList = relem.SelectNodes(rsXPath) Dim lDummy : lDummy = oList.length 'Fill list For Each oNode in oList oNode.parentNode.removeChild oNode Next End Sub Function FromISO8601(s) ' Returns date in local time if timezone not present or GMT if timezone is present FromISO8601 = DateSerial(Mid(s,1,4), Mid(s,5,2), Mid(s,7,2)) If Len(s) > 8 Then FromISO8601 = FromISO8601 + CDate(Mid(s,10,8)) End If If Len(s) > 17 Then FromISO8601 = FromISO8601 - CInt(Mid(s,18,1) & "1") * CDate(Mid(s,19,5)) End If End Function Function ToISO8601(rdat) Dim sYMD : sYMD = CStr((Year(rdat)*100 + Month(rdat) )*100 + Day(rdat)) Dim sHMS : sHMS = Right((Hour(rdat)*100+Minute(rdat))*100+Second(rdat)+1e7, 6) ToISO8601 = sYMD & "T" & Left(sHMS, 2) & ":" & Mid(sHMS, 3,2) & ":" & Right(sHMS, 2) End Function Function AddElem(roParent, rsName, rvntValue) Set AddElem = roParent.ownerDocument.createElement(rsName) roParent.appendChild AddElem If Not IsNull(rvntValue) Then AddElem.Text = rvntValue End Function %> Its not a good idea to attempt to build XML output using response writes. The code does not properly encode characters that have meaning in XML nor was the character encoding correct. Had any files contained a & or a character outside the base ASCII range the generated output would be corrupt. My code uses DOM to build the XML, it makes the code much more readable as well. Note that my code uses ISO8601 formating for the date values all the original code. Also it does not even attempt to place path info into the XML nor does it include counts or size totals. All of these pieces of info can be derived from the XML. I have included your request to drop files found in the data folder itself although I would have prefered that the data folder not have other files in it. (Caveat, the folder name 'data' is case sensitive). Call this page like this:- /root/listnewfiles.asp?cutoff=20080819T21:30:00 What do you do with this XML once received? -- |