Checking file existence

One little piece of code that i have always found handy, is the ability to check and see if a file exists. I dont know where i got this code - it was a long time ago, but i thought what can i lose!??! I have heard you can check and see if a file exists with an API... well this dosent involve an API, and its only a couple lines!

dim fLen as integer, filepath as string
filepath = "C:\myfile.txt"
on error resume next
fLen = len(dir$(filepath))
if err or fLen = 0 then
'file dosent exist
else
'file exists
end if

You might also like...

Comments

Will Urbanski

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“PHP is a minor evil perpetrated and created by incompetent amateurs, whereas Perl is a great and insidious evil perpetrated by skilled but perverted professionals.” - Jon Ribbens