Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GetFiles() filter in DirectoryInfo()
Message
De
04/05/2009 06:09:57
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
 
À
03/05/2009 21:22:46
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01397697
Message ID:
01397726
Vues:
34
>I have been using that since a while but I just realized there is a behavior I was not aware of.
>
>Let's say I have this code:
>
>
>            Dim loDirectory As New DirectoryInfo(cDirectory)
>            Dim loFile As FileInfo
>
>            ' Get all the files in the directory
>            For Each loFile In loDirectory.GetFiles(cFilter)
>                ...
>            Next
>
>
>...with cFilter equals to "*.crp", this would retreive the files with extension "crp". But, if I have some files with a filename such as "MyFile.crp2", this would be retrieved as well. It might have been a coincidence I didn't see that before. How can I assure that a filter to "*.crp", would only retrieve those files and not files with a name such as "MyFile.crp2"?

You can use a Linq query instead which is much more intuitive:
Dim loDirectory As New DirectoryInfo(cDirectory)

for Each loFile in loDirectory.GetFiles().Where( Function(f)  f.Extension.ToLower() = ".crp" )
...
Next
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform