Connecting Tech Pros Worldwide Forums | Help | Site Map

question about file.exists and wildcards

Lou
Guest
 
Posts: n/a
#1: Feb 4 '06
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.

Kevin Spencer
Guest
 
Posts: n/a
#2: Feb 4 '06

re: question about file.exists and wildcards


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" <Lou@discussions.microsoft.com> wrote in message
news:9FE1404F-7D20-4FC3-B7B7-21CCDE2E03FF@microsoft.com...[color=blue]
> 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.[/color]


Sinu
Guest
 
Posts: n/a
#3: Feb 4 '06

re: question about file.exists and wildcards


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:
[color=blue]
> 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.[/color]
Kevin Spencer
Guest
 
Posts: n/a
#4: Feb 5 '06

re: question about file.exists and wildcards


> 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" <Sinu@discussions.microsoft.com> wrote in message
news:022006DD-2C37-41B7-8FB2-57D98EAB113A@microsoft.com...[color=blue]
> 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:
>[color=green]
>> 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.[/color][/color]


Closed Thread


Similar .NET Framework bytes