|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
LINQ - GetDirectories that contain specific filesdefined paths: Private Sub AddFolders(ByVal ParentNode As TreeNode) 'Load the Folders to exclude from the listview Dim xFolders = From f In XDocument.Parse(My.Resources.ExludeFolders).Descendants("FolderPath") _ Select f.Value 'Get the folders under the ParentNode Dim folders = From folder In New DirectoryInfo(ParentNode.Tag).GetDirectories() _ Where Not xFolders.Contains(folder.FullName) _ Select folder 'Add them to the Directory tree For Each folder In folders Dim N = ParentNode.Nodes.Add(folder.Name) N.Tag = folder.FullName Next End Sub What I would also now like to do is only include folders which contains specific file types (*.dft) - or exclude ones that don't. I'm trying the code below but I'm getting warning "Runtime errors might occur when converting 'System.Collections.Generic.IEnumerable(Of String)' to 'String'" Dim folders = From folder In New DirectoryInfo(ParentNode.Tag).GetDirectories() _ Where folder.FullName.Contains(From d In folder.GetFiles("*.dft", SearchOption.TopDirectoryOnly) Select d.FullName) _ And Not xFolders.Contains(folder.FullName) _ Select folder Any suggestions? Scott Rymer schrieb:
Show quoteHide quote > What I would also now like to do is only include folders which contains "FullName.Contains()" expects a string as its argument.> specific file types (*.dft) - or exclude ones that don't. I'm trying > the code below but I'm getting warning "Runtime errors might occur when > converting 'System.Collections.Generic.IEnumerable(Of String)' to 'String'" > > Dim folders = From folder In New > DirectoryInfo(ParentNode.Tag).GetDirectories() _ > Where folder.FullName.Contains(From d In > folder.GetFiles("*.dft", SearchOption.TopDirectoryOnly) Select > d.FullName) _ > And Not xFolders.Contains(folder.FullName) _ > Select folder > > Any suggestions? Your LINQ-subquery "From d In folder.GetFiles("*.dft", SearchOption.TopDirectoryOnly" provides an IEnumerable Of string. So that won't work. If you only want the directories returned that contain *.dft Any() is a pretty good extension method to do the test: Dim folders = From folder In _ New DirectoryInfo(ParentNode.Tag).GetDirectories() _ Where (From f In folder.GetFiles("*.dft", _ SearchOption.TopDirectoryOnly)).Any() _ And Not xFolders.Contains(folder.FullName _ Select folder MfG, Alex
Send Email Using VB 2008 Express
Detecting Design Time vs Run Time Property Set action Problem with turning off Appication Frameworks and with posting al Email Archive program Compilation error Structures inside structures Test - dont bother to read Drawing images in asp.net Vb.net[2008] Combo box population from text file (40,000 lines!) BigInteger and BigDecimal [equivalents] for VB.NET? |
|||||||||||||||||||||||