Check File Existence? 
Author Message
 Check File Existence?

I want to check if a file exists. So, if I have a file name of
'C:\MyDir\MyFile.ext' and I want to check if it exists, what is the
easiest/shortest code way? I can loop through the directory, but I figure
there must be a more direct way. Also, I'd like to be able to check for
existence of *any* files with a particular extension in a given directory. I
tried using the System.IO.FileInfo class, but I can't figure out how to
point it toward a filename.

Code is most appreciated.

I am presently using the System.IO.Directory object (.GetFiles member) to
loop through and identify files. It works, but seems cumbersome.



Wed, 21 Sep 2005 06:09:06 GMT  
 Check File Existence?
System.IO.File.Exists(Filename with complete path)


Quote:
> I want to check if a file exists. So, if I have a file name of
> 'C:\MyDir\MyFile.ext' and I want to check if it exists, what is the
> easiest/shortest code way? I can loop through the directory, but I figure
> there must be a more direct way. Also, I'd like to be able to check for
> existence of *any* files with a particular extension in a given directory.
I
> tried using the System.IO.FileInfo class, but I can't figure out how to
> point it toward a filename.

> Code is most appreciated.

> I am presently using the System.IO.Directory object (.GetFiles member) to
> loop through and identify files. It works, but seems cumbersome.



Wed, 21 Sep 2005 06:31:33 GMT  
 Check File Existence?
Hi JasonP, try using System.IO.File.Exists("C:\MyDir\MyFile.ext"):

If System.IO.File.Exists("C:\MyDir\MyFile.ext") Then
    ' It lives!!
End If

--
==============================================
Happy to Help,
Tom Spink

http://dotnetx.betasafe.com > .NET code (soon)

One Day,

Quote:
> I want to check if a file exists. So, if I have a file name of
> 'C:\MyDir\MyFile.ext' and I want to check if it exists, what is the
> easiest/shortest code way? I can loop through the directory, but I figure
> there must be a more direct way. Also, I'd like to be able to check for
> existence of *any* files with a particular extension in a given directory.
I
> tried using the System.IO.FileInfo class, but I can't figure out how to
> point it toward a filename.

> Code is most appreciated.

> I am presently using the System.IO.Directory object (.GetFiles member) to
> loop through and identify files. It works, but seems cumbersome.



Wed, 21 Sep 2005 06:52:36 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to check file existence?

2. A2K Check for Existence of Back End File

3. Checking for the existence of a file

4. How to check for existence of a file on harddisk form OL VBscript

5. Checking for the Existence of a File

6. Checking for random file existence in Visual Basic

7. Checking for existence of a file???

8. Check for existence of a file?

9. Checking for existence of a file...

10. Check for the existence of a file.

11. Checking the Existence of a File

12. Newbie Question: File existence checking

 

 
Powered by phpBB® Forum Software