473,666 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Fastest FSO loop question

Well I have seen this posted before and haven't seen much in response.

My application has to browse through various folders and find file names.
Sometimes these folders can have thousands of files in them, and of course
looping through each file to find the right one can take a bit of time.

I'm using classic ASP and was wondering if there are any other methods
available to speed up this process other than hardware upgrades.

My application does a search based on an "index" number. All files start
with this index number but might have different file extentions. It then
displays the all the files for the queried index. The requirement is to
display all the files for a given index, not just a specific file.
example:
1234 file.doc
1234 file.jpg
1234 file.pdf

Code:
For Each fl in fc
fileIndex = Left(fl.name,In Str(fl.name," "))
if fileIndex = findex & " " Then
Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name &
"</a>|")
End if
Next

I have read here that using WITH can speed this up but I haven't been able
to see any real improvement.

Code:
with response
For Each fl in fc
fileIndex = Left(fl.name,In Str(fl.name," "))
if fileIndex = findex & " " Then
Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name &
"</a>|")
End if
Next
end with

Any other tips or tricks would be appreciated.

Thanks from this ASP newbie
Jul 19 '05 #1
8 3052
> I have read here that using WITH can speed this up but I haven't been able
to see any real improvement.

Code:
with response
For Each fl in fc
fileIndex = Left(fl.name,In Str(fl.name," "))
if fileIndex = findex & " " Then
Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name &
"</a>|")
End if
Next
end with


When you use "with response", you should be able to leave out the "Response"
when you're writing the line...

Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name &
"</a>|")
should become
..write ("|<a href ='" & webpath & fl.name & "' >" & fl.name & "</a>|")

I'm not sure this will speed up this process much though.
Jul 19 '05 #2
I don't know that this would be the best solution, but I'd at least try it:

Dim sDirRoot, sOutputFile, sSearch, sFileList
sDirRoot = "D:\ThePathOnYo urServerWithThe FilesYouWantToS ee\"
sSearch = "1234"
sOutputFile = "D:\SomePathOnY ourServer\" & sSearch & ".txt"
'''run dir C:\path\1234* and pipe out to a file
Server.CreateOb ject("WScript.S hell").Run "cmd.exe /c dir /B " & sDirRoot &
sSearch & "*>" & sOutputFile, 0, True
sFileList =
Server.CreateOb ject("Scripting .FileSystemObje ct").OpenTextFi le(sOutputFile,
1).ReadAll
That would then leave you with a list like:
1234 file.doc
1234 file.jpg
1234 file.pdf

in a string variable, and you can do with it what you like then.

Permissions for writing the output file and executing cmd.exe would need to
be considered.
Two people accessing the page at the same time would need to be considered.
(You may even want to only have a new output file created if an existing one
is older than a certain date, depending on your needs, or you may want to
generate random filenames by session to avoid overwrites.)

Ray at work


"David P. Jessup" <davidATimntDAS HtechDOTcom> wrote in message
news:eC******** *****@tk2msftng p13.phx.gbl...
Well I have seen this posted before and haven't seen much in response.

My application has to browse through various folders and find file names.
Sometimes these folders can have thousands of files in them, and of course
looping through each file to find the right one can take a bit of time.

I'm using classic ASP and was wondering if there are any other methods
available to speed up this process other than hardware upgrades.

My application does a search based on an "index" number. All files start
with this index number but might have different file extentions. It then
displays the all the files for the queried index. The requirement is to
display all the files for a given index, not just a specific file.
example:
1234 file.doc
1234 file.jpg
1234 file.pdf

Jul 19 '05 #3
> '''run dir C:\path\1234*

Might also add /b switch to the dir command (brief) for a wee bit of
efficiency.
Jul 19 '05 #4
I did include the /B.

Ray at work

"Aaron Bertrand - MVP" <aa***@TRASHasp faq.com> wrote in message
news:OR******** ******@tk2msftn gp13.phx.gbl...
'''run dir C:\path\1234*


Might also add /b switch to the dir command (brief) for a wee bit of
efficiency.

Jul 19 '05 #5
Sorry, I was looking at THIS line, which did not:

'''run dir C:\path\1234* and pipe out to a file

I did include the /B.

Jul 19 '05 #6
I comment miserably... Most of my comments are completely useless and only
say things like:

''The code below is completely idiotic, but I don't have time to do things
right.

Excuses, excuses...

Ray at work

"Aaron Bertrand - MVP" <aa***@TRASHasp faq.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Sorry, I was looking at THIS line, which did not:

'''run dir C:\path\1234* and pipe out to a file

I did include the /B.


Jul 19 '05 #7
> I comment miserably...

Yep.

Oh, you mean in code. Ahhh. Ok.

;-)
Jul 19 '05 #8
Also, if you use one of the last two options you could do something like
(shown for option three):

For Each fl in fc

fileName = fl.name ' copy property to local variable - faster??

' If the length of your index is constant (0000-9999 maybe) then define
this outside of the For Each loop.
' If the length varies by file (e.g. 0-9999) then leave it here.
MaxLevels = InStr (fileName, " ") - 1 ' this gets rid of one call to
'Left' per file.

For Level = 1 to MaxLevels
If (Left (fileName, Level) = Left (findex, Level)) Then
Response.write ("|<a href ='" & webpath & fl.name & "'" &
fl.name & "</a>|")
End If
Next

Next

Try that too :)

Alan

"Alan" <SP************ ******@inspire. net.nz> wrote in message
news:#K******** ******@TK2MSFTN GP12.phx.gbl...
I'm going to do you a disservice here and NOT back up any of these
suggestions with experimental code or timings or anything - I don't even
know if my assumptions are accurate. I'm going to use the weak excuse of
having too many clients that want me to do work for them instead:) I would
be really interested in your results though, if you, say, populated a
directory with a few thousand of these files and tried the approaches that
people have suggested.
For Each fl in fc
fileIndex = Left(fl.name,In Str(fl.name," "))
if fileIndex = findex & " " Then
Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name & "</a>|")
End if
Next
1. Remove the spaces:
if fileIndex = findex & " " Then


Don't concatenate the space. Instead remove the trailing space from
fileIndex. Also, the subtype of these vars is probably String at the

moment (because of the space) - get rid of the space and then:

2. Cast subtypes to Int:

Perhaps integer comparison is faster than string comparison. Assuming no
space:
if (CInt (fileIndex) = CInt (findex)) Then
3. Progressive Checking:

I don't know how these files indexes are used or what typical search
criteria are, but assuming a sequential ordering you could try

progressively checking to see if the fileIndex matches. This would mean fewer checks at
each level before the algorithm gets a chance to move on. Again, you'd have to experiment with string and integer comparisons. This is gash but you get the idea:

For Each fl in fc

fileName = fl.name
fileIndex = Left (fileName, InStr(fl.name," ")-1)

If (Left (fileName, 1) = Left (findex, 1)) Then
If (Left (fileName, 2) = Left (findex, 2)) Then
If (Left (fileName, 3) = Left (findex, 3)) Then
If (Left (fileName, 4) = Left (findex, 4)) Then
Response.write ("|<a href ='" & webpath & fl.name & "'
" & fl.name & "</a>|") End If
End If
End If
End if
Next

4. Compare next char only:

Vary the previous method to only check each subsequent char/int instead of
the previously checked ones too. That is, instead of using Left (findex,

2) in the second conditional, just check the second char in findex - you
already know the first char is a match. This will depend on the efficiency
of Left cf. something like Instr.

Make sure you let us know how you go.

Alan

"David P. Jessup" <davidATimntDAS HtechDOTcom> wrote in message
news:eC******** *****@tk2msftng p13.phx.gbl...
Well I have seen this posted before and haven't seen much in response.

My application has to browse through various folders and find file names. Sometimes these folders can have thousands of files in them, and of course looping through each file to find the right one can take a bit of time.

I'm using classic ASP and was wondering if there are any other methods
available to speed up this process other than hardware upgrades.

My application does a search based on an "index" number. All files start with this index number but might have different file extentions. It then
displays the all the files for the queried index. The requirement is to
display all the files for a given index, not just a specific file.
example:
1234 file.doc
1234 file.jpg
1234 file.pdf

Code:
For Each fl in fc
fileIndex = Left(fl.name,In Str(fl.name," "))
if fileIndex = findex & " " Then
Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name & "</a>|")
End if
Next

I have read here that using WITH can speed this up but I haven't been able to see any real improvement.

Code:
with response
For Each fl in fc
fileIndex = Left(fl.name,In Str(fl.name," "))
if fileIndex = findex & " " Then
Response.write ("|<a href ='" & webpath & fl.name & "' >" & fl.name & "</a>|")
End if
Next
end with

Any other tips or tricks would be appreciated.

Thanks from this ASP newbie


Jul 19 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2534
by: Simon | last post by:
Hi, If I have a string, (variable len), and I am looking for the first position of one char in array starting from position 'x' For example, // the 'haystack' $string = "PHP is great, php is ok"; // the needles
9
32595
by: Rune Strand | last post by:
Hi, If I have a lot of integers and want do something with each digit as integer, what is the fastest way to get there? Eg. Make 12345 into an iterable object, like or "12345" (Btw: What is the English term for this process; itemize? tokenize? digitize? sequence?) Some examples:
6
4875
by: Neal D. Becker | last post by:
I need a fairly small lookup table, and I'm wondering which data python data structure would be fastest. I could use a list, tuple, dictionary, numeric array, or maybe plain python array. The table would be indexed by simple integers and would be dense (filled).
17
2311
by: DraguVaso | last post by:
Hi, I need to find the FASTEST way to get a string in a Loop, that goes from "a" to "ZZZZZZZZZZZZZZZZZ". So it has to go like this: a b .... z
354
15791
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets hooked up to interfaces. The Gtk is more than enough gui.
0
1504
by: chad kline | last post by:
i have searched around for an answer to this question, but haven't found a satisfactory answer. i understand things like mmap(2) can be used to quickly load a file - but it seems to be a function for "read-only" situtations. it doesn't appear to be useful in situations where editing must be done on the loaded file. the next fastest method (based on my searches) seemed to be a fread(3)/read(2) loop. however, malloc(3)'s seems to slow
14
8322
by: romayankin | last post by:
Hello All, I'm writing cross-platform code so i'm bound to standards. Here is the code I have: ~~~~~~~~~~~~~~~~~~ double **mx = new double*; for(int i = 0; i < col - 1; i++) { mx = new double; sizeOfMx += sizeof(double) * row; }
44
3216
by: Don Kim | last post by:
Ok, so I posted a rant earlier about the lack of marketing for C++/CLI, and it forked over into another rant about which was the faster compiler. Some said C# was just as fast as C++/CLI, whereas others said C++/CLI was more optimized. Anyway, I wrote up some very simple test code, and at least on my computer C++/CLI came out the fastest. Here's the sample code, and just for good measure I wrote one in java, and it was the slowest! ;-)...
30
9057
by: Chaos | last post by:
As my first attempt to loop through every pixel of an image, I used for thisY in range(0, thisHeight): for thisX in range(0, thisWidth): #Actions here for Pixel thisX, thisY But it takes 450-1000 milliseconds I want speeds less than 10 milliseconds
24
2287
by: ThunderMusic | last post by:
Hi, The subject says it all... I want to use a byte and use it as byte* so I can increment the pointer to iterate through it. What is the fastest way of doing so in C#? Thanks ThunderMusic
0
8444
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8869
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8639
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2771
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.