Just remember that there is a gotcha when using the
Dim files() As String = System.IO.Directory.GetFiles(path, "*.txt")
functionality where the pattern has a 3 character extension. This will
return information for any file in path having an extension that starts with
..txt, (i.e., .txta, .txtb, .txtaa, .txtab, etc.). For extensions of any
other length this is not an issue. Don't ask me why the Redmond gurus made
it that way (I see it as a bug), but it's in the doc's as a design feature.
So, for the example to work correclty it needs to be:
Dim _ss() As String = System.IO.Directory.GetFiles("C:\foo", "*.exe")
Dim _f As Boolean = False
For Each _s As String In _ss
If System.IO.Path.GetExtension(_s) = ".exe") Then
_f = True
Exit For
End If
Next
If _f Then
MsgBox("File(s) exist!")
Else
MsgBox("Files do not exist!")
End If
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:2h************@uni-berlin.de...
* y1***@yahoo.com (Mike) scripsit: I am looking for function in .Net library that let me know if exist
any file if I specified template.
Eg: I specify "*.txt" and if any file (1.txt, 2.txt, .. ) exists then
I can get True or at least file name . And if does not exist Fasle or
empty string.
\\\
If System.IO.Directory.GetFiles("C:\foo\*.exe").Lengt h > 0 Then
MsgBox("File(s) exist!")
Else
MsgBox("Files do not exist!")
End If
///
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>