Link to home
Start Free TrialLog in
Avatar of Mik Mak
Mik Mak

asked on

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

Dir("c:\")
or
My.Computer.FileSystem.FileExists("c:\")

Any help would be much appreciated
ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mik Mak
Mik Mak

ASKER

I think you're right :) - but what if I need to check in a subfolder - do I then also use double-forward slash ?
Use this way... And i'm assuming you want to check for abc.xlsx file

dim filename as string,xpath as string

xpath="C:\"
Filename="abc.xlsx"

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

Open in new window


Saurabh...
Avatar of Mik Mak

ASKER

Hmm, now it also Work with backslash - I'm confused :)
Bojerene,

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...

Saurabh...