By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,688 Members | 1,900 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,688 IT Pros & Developers. It's quick & easy.

How do I check if a file exists (A97)

P: n/a
pw
Hi,

I need to check if a particular .jpg (complete with the path name)
exists.

How would I do that?

Thanks,
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)
Nov 13 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
if dir$("file.jpg")="" then
msgbox "file.jpg does not exit"
endif

"pw" <***paulwilliamson@***spamcop.net> wrote in message
news:k1********************************@4ax.com...
Hi,

I need to check if a particular .jpg (complete with the path name)
exists.

How would I do that?

Thanks,
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)

Nov 13 '05 #2

P: n/a
pw
>if dir$("file.jpg")="" then
msgbox "file.jpg does not exit"
endif

Thank you!!
"pw" <***paulwilliamson@***spamcop.net> wrote in message
news:k1********************************@4ax.com.. .
Hi,

I need to check if a particular .jpg (complete with the path name)
exists.

How would I do that?

Thanks,
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)


-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)
Nov 13 '05 #3

P: n/a
pw wrote:
Hi,

I need to check if a particular .jpg (complete with the path name)
exists.

How would I do that?

Thanks,
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)


Use the old DOS command, updated to a VB function.
Dir()

If Dir("C:\Test\Test.jpg") > "" Then blah-de-blah
Nov 13 '05 #4

P: n/a
RE/
How would I do that?


One way:
------------------------------------------
Function fileExist(ByVal theFilePath As Variant) As Integer
debugStackPush mModuleName & ": fileExist"
On Error GoTo fileExist_err

' PURPOSE: To determine whether-or-not a file exists
' ACCEPTS: A full path to the file in question
' RETURNS: True or False depending...

Dim skipLine As String

fileExist = (Dir$(theFilePath) <> "")

fileExist_xit:
debugStackPop
On Error Resume Next
Exit Function

fileExist_err:
Select Case Err
Case 71
MsgBox "That path refers to a floppy disk. Please insert the disk.", 49,
"Insert Disk"

Case 76
'(We expect 76 if no file found)

Case 68
skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)
MsgBox "The system has reported that drive " & UCase$(Left$(theFilePath,
2)) & " is unavailable." & skipLine & "One possibility is that you specified the
wrong drive; another is that there is a problem with your LAN logon.", 16,
"Cannot find Drive"

Case Else
bugAlert True, ""
End Select

Resume fileExist_xit
End Function
------------------------------------------
--
PeteCresswell
Nov 13 '05 #5

P: n/a
pw
>pw wrote:
Hi,

I need to check if a particular .jpg (complete with the path name)
exists.

How would I do that?

Thanks,
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)


Use the old DOS command, updated to a VB function.
Dir()

If Dir("C:\Test\Test.jpg") > "" Then blah-de-blah


Thank you.
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)
Nov 13 '05 #6

P: n/a
pw
>RE/
How would I do that?


One way:
------------------------------------------
Function fileExist(ByVal theFilePath As Variant) As Integer
debugStackPush mModuleName & ": fileExist"
On Error GoTo fileExist_err

' PURPOSE: To determine whether-or-not a file exists
' ACCEPTS: A full path to the file in question
' RETURNS: True or False depending...

Dim skipLine As String

fileExist = (Dir$(theFilePath) <> "")

fileExist_xit:
debugStackPop
On Error Resume Next
Exit Function

fileExist_err:
Select Case Err
Case 71
MsgBox "That path refers to a floppy disk. Please insert the disk.", 49,
"Insert Disk"

Case 76
'(We expect 76 if no file found)

Case 68
skipLine = Chr$(13) & Chr$(10) & Chr$(13) & Chr$(10)
MsgBox "The system has reported that drive " & UCase$(Left$(theFilePath,
2)) & " is unavailable." & skipLine & "One possibility is that you specified the
wrong drive; another is that there is a problem with your LAN logon.", 16,
"Cannot find Drive"

Case Else
bugAlert True, ""
End Select

Resume fileExist_xit
End Function
------------------------------------------


Thanks Pete!
-pw
remove astericks (*) from e-mail address
(use paulwilliamson at spamcop dot net)
Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.