469,579 Members | 1,063 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

How do you determine if a file exists before using the StranmReader object?

Is there any better method of determining if a file exists then using the Scripting.FileSystemObject

If I do thi

Dim fs As New System.IO.StreamReader(FileName

and the file does not exist thena n exception is thrown, how can you determine if the file exists before attemptng to open it
Nov 20 '05 #1
8 1460
Yes,

Try:

If System.IO.File.Exists(Filename) Then
....
... Your Code ...
....
End If

--
Regards
Simon Jefferies
Tools Programmer, Headfirst Productions
mailto:si****@headfirst.co.uk
www.headfirst.co.uk www.callofcthulhu.com
-
"Darrell Wesley" <an*******@discussions.microsoft.com> wrote in message
news:93**********************************@microsof t.com...
Is there any better method of determining if a file exists then using the
Scripting.FileSystemObject?

If I do this

Dim fs As New System.IO.StreamReader(FileName)

and the file does not exist thena n exception is thrown, how can you
determine if the file exists before attemptng to open it?

Nov 20 '05 #2
"Darrell Wesley" <an*******@discussions.microsoft.com> schrieb
Is there any better method of determining if a file exists then using
the Scripting.FileSystemObject?


io.file.exists(filename)
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "Armin Zingler" <az*******@freenet.de> scripsit:
"Darrell Wesley" <an*******@discussions.microsoft.com> schrieb
Is there any better method of determining if a file exists then using
the Scripting.FileSystemObject?


io.file.exists(filename)


.... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #4
Hi Herfried,
io.file.exists(filename)


... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


Vb is not case sensitive and let's keep it that way

Cor
Nov 20 '05 #5
Cor,

* "Cor Ligthert" <no**********@planet.nl> scripsit:
io.file.exists(filename)


... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


Vb is not case sensitive and let's keep it that way


I didn't "complain" about case sensitivity but about "qualification" of
a class name with an incomplete namespace hierarchy.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
"Darrell Wesley" <an*******@discussions.microsoft.com> schrieb
Is there any better method of determining if a file exists then
using the Scripting.FileSystemObject?


io.file.exists(filename)


... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


I don't see the difference.
--
Armin

Nov 20 '05 #7
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Cor,

* "Cor Ligthert" <no**********@planet.nl> scripsit:
io.file.exists(filename)

... that should be forbidden with 'Option Strict On' too!
'System.IO.File.Exists' ;-).


Vb is not case sensitive and let's keep it that way


I didn't "complain" about case sensitivity but about "qualification"
of a class name with an incomplete namespace hierarchy.


System is imported by default.
--
Armin

Nov 20 '05 #8
Herfried,

Sorry I am such a superdummy

:-)))))))))))))))

(Of course I did understand what you mean but that answer would come from
Armin as it was)

Cor
Nov 20 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Christopher W. Douglas | last post: by
3 posts views Thread by Web Webon | last post: by
9 posts views Thread by Adam | last post: by
2 posts views Thread by Wayne Wengert | last post: by
7 posts views Thread by Stephen E. Weber | last post: by
17 posts views Thread by Peter Duniho | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.