Connecting Tech Pros Worldwide Help | Site Map

Problem trying to determine if a file exists using wildcard

Dan W
Guest
 
Posts: n/a
#1: Nov 21 '05
Hi there. I am parsing a text file and as I parse each line I need
to go out to two different directories and check to see if any files
beginning with the string I just parsed exist. For example... if the
first line in my text file is AS1501 then I need to check Dir1 and see
if there are any files that begin with AS1501 then I need to go to
Dir2 and check there also. I am trying to check using the following
code...

If File.Exists(Dir1 + "\" + subDir + "\" + pString + "*.pdf") Then
Do some stuff
End If

I used a messagebox to verify that the string that's being built does
point to the correct place and I've verified that the .pdf file I am
trying to check for does exist. However, when I put this IF THEN
statement in it never finds the file. I assume that this is because
it is seeing the asterisk as a literal asterisk rather than a wildcard
symbol. Just wondering if there is any way around this.

I'm new to vb.net and any help would be greatly appreciated.

Thanks!
Armin Zingler
Guest
 
Posts: n/a
#2: Nov 21 '05

re: Problem trying to determine if a file exists using wildcard


"Dan W" <me@here.com> schrieb[color=blue]
> Hi there. I am parsing a text file and as I parse each line I need
> to go out to two different directories and check to see if any files
> beginning with the st
> ringIjustparsedexist.Forexample...ifthe first line in my text file
> is AS1501 then I need to check Dir1 and see if there are any files
> that begin with AS1501 then I need to go to Dir2 and check there
> also. I am trying to check using the following code...
>
> If File.Exists(Dir1 + "\" + subDir + "\" + pString + "*.pdf") Then
> Do some stuff
> End If[/color]

The wildcard '*' is not a valid char in a file name.


Armin
briktal
Guest
 
Posts: n/a
#3: Nov 21 '05

re: Problem trying to determine if a file exists using wildcard


One thing you could do, not sure if it is the best way or not, is to
use System.IO.Directory.GetFiles(). It takes the path to search and
the search pattern and returns a string() containing all the files that
match. So, you could do Directory.GetFiles(whateverpath, "*.pdf") then
check the return value.

Dan W
Guest
 
Posts: n/a
#4: Nov 21 '05

re: Problem trying to determine if a file exists using wildcard


Thank you very much. Using this method seems to have done the trick.
Thanks again.

Cheers!

On 22 Aug 2005 08:01:43 -0700, "briktal" <briktal@gmail.com> wrote:
[color=blue]
>One thing you could do, not sure if it is the best way or not, is to
>use System.IO.Directory.GetFiles(). It takes the path to search and
>the search pattern and returns a string() containing all the files that
>match. So, you could do Directory.GetFiles(whateverpath, "*.pdf") then
>check the return value.[/color]

Closed Thread