FileExists in VS 2005 VB always returns false

I'm having issues with a simple FileExist check in old VS 2005 VB project that I need to make som alterations to.

The check for a file always returs false  - not matter if I use


Any help would be much appreciated
Mik MakConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:

I think you are checking for the drive not the file.

try this

This example checks to see whether or not the file Check.txt exists and supplies the information in a message box.

If My.Computer.FileSystem.FileExists("c://Check.txt") Then
    MsgBox("File found.")
    MsgBox("File not found.")
End If

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mik MakConsultantAuthor Commented:
I think you're right :) - but what if I need to check in a subfolder - do I then also use double-forward slash ?
Saurabh Singh TeotiaCommented:
Use this way... And i'm assuming you want to check for abc.xlsx file

dim filename as string,xpath as string


If Len(Dir(xpath &  filename)) = 0 Then
  MsgBox "File does not exist"
'your code here
end if

Open in new window

Mik MakConsultantAuthor Commented:
Hmm, now it also Work with backslash - I'm confused :)
Saurabh Singh TeotiaCommented:

In order it to work you need to define the file name in it which was missing once you define the file name and check for len that way you can trap whether file is their or not...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.