Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

speeding up filesearch on remote machine 1

Status
Not open for further replies.
Mar 10, 2004
53
US
I'm trying to find specific files based on costcenter and date embedded in the filename of a text file.

The files are not in the webserver and contains over 7000 files totalling 400+mb (each file is around 10Kb).

Don't have any problems with the files. Problem is, it is taking too long to find them (1 1/2 minutes).

Is there any way to speed this up?

TIA-


dim prDate, prThtr
prDate = CDate(Request("strSDate"))
prThtr = Request("strThr")
findsls = instr(prThtr,";")
prThtr = mid(prThtr,findsls+1)

'Create the File Object to retrieve the Files.
Set fso = CreateObject("Scripting.FileSystemObject")
Set foldr = fso.GetFolder(sPP)
Set allfile = foldr.Files

dim site

site = mid(request("strThr"),1,6)

dim costcenter, filedate
dim dateArray(7,2)
dim x

For x = 0 to 6
dateArray(x,1) = dateadd("d", -1 * x, prDate)
Next 'x

For Each objItem In foldr.Files
costcenter = mid(objItem.Name,1,6)

filedate = mid(objItem.Name,8,2) & "/" & mid(objItem.Name,10,2) & "/" & mid(objItem.Name,12,4)
if costcenter = site then
for y = 0 to 6
if cdate(filedate) = dateArray(y,1) then
dateArray(y,2) = "Transmitted"

end if
next 'y


%>



<%
end if


Next 'objItem

for z = 0 to 6
response.write "<tr bgcolor = 'lightgrey'>" & vbCrLF
response.write "<td> " & weekdayname(weekday(dateArray(z,1))) & ", " & dateArray(z,1) & "</td>"
response.write "<td> " & dateArray(z,2) & "</td></tr>"
next 'z

%>


<%
'Set allff = nothing
Set fso = nothing
Set foldr = nothing
Set allfile = nothing
%>
 
Ouch, your looping through 7000 files? S..I have had problems with Windows dealing with 1000's of files that went well past the minute and a half mark.

Your only bet is going to be to if you can somehow guess what files are there. Pretty much anything you do with windows scripting and 1000's of fils is going to take forever.

One way to speed it up is to take that site string and your possible dates andjust check for the seven files your interested in, rather than pulling all 7000 across, something like:
Code:
Dim dateCtr
For dateCtr = 0 to UBound(dateArray,1)
   If fso.FileExists(sPP & "\" & site & "_" & MakeDateString(dateArray(dateCtr,1))) Then
      dateArray(dateCtr,2) = "Transmitted"
   End If
Next


Function MakeDateString(aDate)
   Dim dStr

   If Month(aDate) < 10 Then
      dStr = "0" & Month(aDate)
   Else
      dStr = Month(aDate)
   End If

   If Day(aDate) < 10 Then
      dStr = dStr & "0" & Day(aDate)
   Else
      dStr = dStr & Day(aDate)
   End If

   dStr = dStr & Year(aDate)

   MakeDateString = dStr
End Function


So basically what this is doing is building a target file string based on the site name from your code, an underscore (that might be wrong, I guesed at what the missing character was), and a date string. This should be faster as the FSO should be checking the validity of the file path rather than attempting to list all of the files (guess this one depends on how MS implemented the FileExists function). You probably need to add an extension to that file, hopefully that isstandard. If you have several posible extensions you can put those in an array and do a secon loop inside the date loop to check for each extension with each date. Even with two loops I think you would be better off than trying to loop through 7000+ files.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
Wow! What an improvement! It takes only a second now for the page to load.

Thank you so much, you've been a big help.
 
Not a problem, I love the questions I haven't seen 50 times already :)

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
Need an expensive ASP developer in the North Carolina area? Feel free to let me know.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top