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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

listing directory files

Status
Not open for further replies.

davejam

Technical User
Jan 6, 2004
313
GB
hi,

i am trying to pull through the filenames for images i need to display from a filesystem in ASP/IIS

basically i've managed to read the folder i want using
Code:
Whichfolder="c:\company shared folders\technicians pictures\"  
Dim fs, f, f1, fc  
Set fs = CreateObject("Scripting.FileSystemObject")  
Set f = fs.GetFolder(Whichfolder)  
Set fc = f.files 

For Each f1 in fc  
 Response.write (f1.name & "<BR>")  
Next

which brings back the filenames from the list but i want to find files that start with a specific code (they take callnumbers from the database) but the next part of the filename is not specifically set as a standard...

is there a way to search the folder for specific part filenames rather than scrolling through and checking, also is it possible to do a quick check to see if files exist in the folder using * clauses... like

Code:
If fs.FileExists("c:\company shared folders\technicians pictures\126597*.*") Then
response.write "yes"
Else
response.write "no"
End If

daveJam

even my shrink says its all your f#@/ing fault
 
why not

For Each f1 in fc
if strcmp(fl.name,"yourfile") then response.write "bingo"

Response.write (f1.name & "<BR>")
Next
 
right... as theres potentially upto 14000 files in a folder i don't want to scan through each one... and from my search through the web its not possible to search a directory for files without going through the entire folder...

as they are currently naming in a convention...

ie...
recID-1-varDATE.jpg
recID-2-varDATE.jpg

i'm simply putting a check in a loop so as long as they're consecutive then it'll display... can't get to the code as the servers not playing ball!!!

so i'm basically saying
a = 0
i = 1
while a <> 1 then
***code i can't remember off the top of my head
*** check photo exists using i as within photo name
if exists
display photo
i = i + 1
else
a = 1
wend

or something to that value

if there is a better way please inform, i'm going with this for now!!!

cheers

daveJam

even my shrink says its all your f#@/ing fault
 

why not just store the url/names of the images in the database ? Then you can add other metadata to that record which you would not be able to get from the file.

Or just make a directory for each record id when you first upload / create the image file and have the files inside with a unique ID of some sort.

Neither are particularly difficult to do, and would be better overall for the purpose you have in mind. I would personally go with either a database table or, depending on how I wanted to use/present the images, an XML file.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
unfortunately i'm building a reporting web end to an already existing system so cannot change the conventions!!!

that'd be more of the approach i'd take if i was doing full management myself!!!

daveJam

even my shrink says its all your f#@/ing fault
 

Is this application owned and managed by your company ?

If so, why not ask them to change it - they must create the files at some point, and adding in the directory creation is minimal effort - maybe 15 lines of code max. That would also help them too.. creating many thousands of files in a single directory will probably start to affect their performance if they need to do any directory listing type functions themselves.

Alternatively, a bit of a hack way would be to index them once a day/hour/etc into a local XML file, then use that for realtime requests (which will be the bigger hit on your server resources, hence why you want to minimise looping through 14000 anythings).



A smile is worth a thousand kind words. So smile, it's easy! :)
 
This is a wild guess but you might be able to use the WScript.Shell object and parse the response from something like [tt]dir *.jpg[/tt] to achieve this...

 

I reckon that would work Sheco. Worth the OP giving it a try.

I vaguely remember another way to do this too, it included setting a Pattern property for some object or other (not very standard mind), though I can't for the life of me find the example script I wrote, and assume it's using something a little out of the ordinary, so may not be available without certain components being available.


A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top