By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,977 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,977 IT Pros & Developers. It's quick & easy.

question about file.exists and wildcards

P: n/a
Lou
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.
Feb 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.

"Lou" <Lo*@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
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.

Feb 4 '06 #2

P: n/a
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
--
Shrinivas Reddy.
Systems Analyst
Satyam Computer Services Ltd.
"Lou" wrote:
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.

Feb 4 '06 #3

P: n/a
> 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.

"Sinu" <Si**@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
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
--
Shrinivas Reddy.
Systems Analyst
Satyam Computer Services Ltd.
"Lou" wrote:
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.

Feb 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.