-
Jan 31st, 2014, 10:27 AM
#1
Thread Starter
Member
Lambda code not working
I'm trying to look through a directory and pick every file that doesn't have a string at the beginning, and I am having a go at doing this with lambdas, but I am getting it wrong somewhere
Code:
Dim di As DirectoryInfo = New DirectoryInfo(My.Settings.str_TargetDir)
Dim fi_AllCSVfiles As FileInfo() = di.GetFiles("*.*", SearchOption.TopDirectoryOnly).Where(Function(x) (x.Name.StartsWith("ENCRYPTED_") = False))
There may be multiple errors in here that are causing me problems, can anyone point them out to me?
cheers!
-
Jan 31st, 2014, 10:42 AM
#2
Thread Starter
Member
Re: Lambda code not working
damn I feel stupid, I just forgot .toarray at the end of the getfiles line.
-
Jan 31st, 2014, 11:13 AM
#3
Re: Lambda code not working
Wait... doesn't GetFiles return an array? It does ... In fact, it's an array of FileInfo... so... why would you need the .ToArray on the end of that? *scratches head*
But, I guess if it works...
-tg
-
Jan 31st, 2014, 11:20 AM
#4
Re: Lambda code not working
Originally Posted by techgnome
Wait... doesn't GetFiles return an array? It does ... In fact, it's an array of FileInfo... so... why would you need the .ToArray on the end of that? *scratches head*
But, I guess if it works...
-tg
You are correct but he pipes that into a linq where clause which will return an IEnumerable(Of T).
This pattern in common to all great programmers I know: they're not experts in something as much as experts in becoming experts in something.
The best programming advice I ever got was to spend my entire career becoming educable. And I suggest you do the same.
-
Jan 31st, 2014, 12:24 PM
#5
Re: Lambda code not working
Oooooh.... ok... he meant a .ToArry at the VERY END.... gotcha... I thought he had done it in the middle... I'm with ya now.
-tg
-
Jan 31st, 2014, 01:21 PM
#6
Re: Lambda code not working
If you're going to use LINQ why not use EnumerateFiles? Can't imagine any performance difference but seems to fit better.
vb Code:
Imports System.IO Public Class Form1 Private Sub Foo() Dim di As New DirectoryInfo("path") Dim csvFiles = di.EnumerateFiles("path").Where(Function(fi) Not fi.Name.StartsWith("ENCRYPTED_")) End Sub End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|