HOWTO compare recordset with a name of a phisical file

E

Emilio Mala

Hello everybody!
If you could help he, I appreciate... thanks!
Lets go to the problem:

- I need compare the recordset from a database and check if the file
exists in a directory.
If exists, I show a picture, case not, I dont show....

Sample:
The result from a recordset was "hawai.jpg"
Then I need to check if the file exists in a directory located in
/images/countries/...
IF exists I show the image
IF NOT I show the message "Sorry, this country doesnt have a picture in
the directory."
Thanks in advance!
Best Regards!
Emilio
 
B

Bullschmidt

To see if a file exists:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(MyFilenameVar) Then...

And here are some FSO resources:

FileSystemObject
http://www.4guysfromrolla.com/webtech/faq/faqtoc.shtml#FileSystemObject
5-part FAQ

Using the FileSystemObject for Web Site Maintenance, Part 2 - 9/14/1999
http://www.4guysfromrolla.com/webtech/091499-1.shtml

Best regards,
J. Paul Schmidt, Classic ASP Web Designer
http://www.Bullschmidt.com
Classic ASP Design Tips, ASP Web Database Demo, ASP Bar Chart Tool...
 
A

Alex Kail

Use this function. The file name must be the path in which it resides
on the machine, not the absolute or relative paths (ie:
c:\images\countrie\hawai.jpg).

Function FileExist(strFileName)

'Declare
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

'Functions returns whether or not the file exists
FileExist = fso.FileExists(strFileName)

'Housekeeping!
Set fso = Nothing

End Function

Here's an example on how I use it:

If FileExist(Server.MapPath("images\countries") & "\hawai.jpg") = True
Then
'This file exists
Else
'This file does not exist
End If
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top