question about file.exists and wildcards

G

Guest

Question:

I can't seem to get file.exists(filename) to return true when I search using
wildcards, and I know there's a file in that dir with that extension.
here's the path


dim yesno as boolean
FileName = "D:\Documents and Settings\Lou\My Documents\Visual Studio
Projects\Lucky7\Lucky7\bin\*.txt"

yesno=file.exists(filename)

file.exists keeps returning false when there is a readme.txt file in that dir.

It works if I explicitly name the file but not with the wildcard.
so...what am I doing wrong?
Thanks for helping this noobie.
 
K

Kevin Spencer

Hi Lou,

The File.Exists(string) method takes a file path as an argument. It does not
support using wildcards, because it is used to determine whether or not a
single file having the file name exists at the location specified. Wildcard
searches return multiple files. The Directory.GetFiles(string, string)
method will return an array of file paths for files in a Directory which
match the search pattern specified. The first argument is the path to the
directory, and the second is the search pattern. If there are no matching
files, the array will be empty.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.
 
G

Guest

You cannot use wildchar search with filenames. The only solution to this is
to use Directory.GetFiles(path, "*.txt"); This returns a list of files which
will match the criteria and you can then enumerate them.
You statement is ABSOLUTLY wrong.
Thanks
 
K

Kevin Spencer

You statement is ABSOLUTLY wrong.

Which "statement?" He was asking a question. Jeez. No need to hammer an
admitted "noobie."

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top