Solved

How to know if a file exists

Posted on 2002-05-10
4
139 Views
Last Modified: 2010-05-02
Has anyone got code to find out if a file exists before I use it in my app.
C
0
Comment
Question by:cuntacinte
  • 2
4 Comments
 
LVL 28

Expert Comment

by:vinnyd79
ID: 7001485
If Dir("C:\Filename.txt") <> "" Then
0
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 50 total points
ID: 7001491
sorry about the above,this is what I meant

if Dir("C:\Filename.txt") <> "" Then
   MsgBox "File Exists!"
end if
0
 

Author Comment

by:cuntacinte
ID: 7001509
Thanks vinnyd79

C
0
 
LVL 4

Expert Comment

by:RichW
ID: 7001516
Function FileExist(Fname As String) As Boolean
    On Local Error Resume Next
   FileExist = (Dir(Fname) <> "")
End Function

' Use
If FileExist("C:\MyFile.txt" Then
   Debug.Print "File Found"
End If

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now