473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I check if a file exists (A97)

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
6 10850
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Joseph Oget | last post by:
If I use the code below in a VB.NET form, even if the file exists, and is then executed, the Else statement produces the "Sorry cannot find the File " error message. The MessageBox.Show(...
10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
6
by: Alex Chan | last post by:
Hi Group, I encountered something strange with File.Exists(string path). This function is simply to check whether a file exists in certain path. However, if the path starts with "file:\" in the...
2
by: Chris Fink | last post by:
I am using the System.IO.File class to determine if a file exists on a network share. The File.Exists method keeps returning false, even though the file does exist. The MSDN documentation...
10
by: Ricardo Luceac | last post by:
Hi all. I'm having a problem with this, I have look if a file exists, if don't wait till it is created and if it exists I need to open it. I do the following: for (; ; ) {
10
by: Julia | last post by:
Hi, there, I am trying to append a binary file by using: FILE *strean; stream = fopen( "c:\temp.dat", "ba+" )); Is there a way that I can check if the file exists or not before fopen,...
7
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not...
8
by: Sweetiecakes | last post by:
In our series of "probably something simple"... I am doing a File.Exists operation to check if a file exists. Let's assume that this file is C:/test.txt. Now, if I do...
2
Manikgisl
by: Manikgisl | last post by:
HI. How to check File exists in Web Share C# try { WebRequest request = HttpWebRequest.Create("http://www.microsoft.com/NonExistantFile.aspx"); request.Method = "HEAD"; // Just get...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.