joehuaba
Goto Top

ComboBox - Except FileType

Guten Morgen face-smile

Ich komme leider nicht weiter, obwohl es wieder nur mal ne Kleinigkeit ist.
Ich entwickle etwas in VB.NET.
Eine Combo-Box ließt aus einem Ordner alle Files aus.
Jetzt will ich aber dass die Box alles ausließt, außer z.b. "*.txt"!
Kann mir jemand weiterhelfen ?

Dim dir = txtConfigurationFolder.Text
For Each file As String In System.IO.Directory.GetFiles(dir)
cmbDeleteGroup.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
cmbAddComputer.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
Next

Content-Key: 271443

Url: https://administrator.de/contentid/271443

Printed on: April 20, 2024 at 00:04 o'clock

Member: colinardo
Solution colinardo May 08, 2015 updated at 09:25:42 (UTC)
Goto Top
Hallo joehuaba,
da gibt es einige Möglichkeiten ... hier zwei davon mit Linq-Expressions:
For Each file As String In System.IO.Directory.GetFiles(dir).Where(Function(s) System.IO.Path.GetExtension(s).toLower() <> ".txt")  
     cmbDeleteGroup.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
     cmbAddComputer.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file)) 
Next
Die Zuweisung zu einer ComboBox geht aber auch ohne Schleife und damit schneller.
cmbDeleteGroup.Items.AddRange(System.IO.Directory.GetFiles(dir).Where(Function(s) System.IO.Path.GetExtension(s).toLower() <> ".txt").Select(Function(s) System.IO.Path.GetFileNameWithoutExtension(s)).ToArray())  
Grüße Uwe
Member: joehuaba
joehuaba May 08, 2015 at 09:25:29 (UTC)
Goto Top
Danke für die Antwort, klappt face-smile
Super !

Ich wünsche ein schönes Wochenende ! face-smile
Member: colinardo
colinardo May 08, 2015 at 09:26:06 (UTC)
Goto Top
Zitat von @joehuaba:
Ich wünsche ein schönes Wochenende ! face-smile
Gleichfalls face-smile