Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

vb.net checking if file exists problem

The following code in a windows service alway returns false:

        Dim f As New IO.FileInfo(sourceFolder)

        If f.Exists = 1 Then
            LogError("FILE EXISTS " & f.FullName)
        Else
            LogError("FILE DOES NOT EXIST " & f.FullName)
        End If

This is the value of f - - C:\FileExchange\Appointments\Pending


And it contains the file -- Text Document.txt

I won't always know the name of the text file, and there may be 1 or more. I need to check that there are files in the folder before I process them.

What wrong?

Andy
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

It's correct in returning false. You are passing the path of a directory and asking if it exists as a file, which it doesn't.

If you want to check for the existence of a file then you need to pass the path AND name of the file.
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland 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
ASKER CERTIFIED SOLUTION
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 Andy Green

ASKER

Thanks All

Andy