FileSearch for VB.Net

  • Thread starter Thread starter Brent McIntyre
  • Start date Start date
B

Brent McIntyre

Good evening all,

I am writing a program which requires me to search for files as I have
done many times in Microsoft Excel Visual Basic for Applications, as per
below.

Set fs = CreateObject("Scripting.FileSystemObject")

With Application.FileSearch
.LookIn = DesktopAddress
.Filename = "*.TXT"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
ComboBox.AddItem .FoundFiles(i)
Next i
Else
Msgbox("There were no valid Files Found !")
End If
End With

Unfortunately I have had no luck in trying to find the equivalent
routines for Microsoft Visual Basic.Net, if anyone could help me it
would be greatly appreciated.

Yours sincerely,

Brent McIntyre
 
Good afternoon Brent,

(Morning just ended here in most parts of Europe)

Look for the fileInfo and directoryInfo class in/on MSDN for this.
There is a lot of information.

I think you will find it?

And if not, give us a reply then (or give it anyhow).

Cor
 
Herfried and Cor,

Thanks for your help so far, I am just having a few annoying issues, the
FileSystemObject routines seem to be the same in VB.Net for everything I
have used thus far, except this one, the solution that Herfried provided
seemed a bit in depth for what I am trying to do, thank you anyway it is
greatly appreciated, I am still learning though and was a bit confused,
especially by the non-english comments (I still find it hard to come to
terms with the fact that newsgroups allow you to have conversations with
people from all over the world). So do you know anyway simpler to get
the names of all text (or other) files in a directory returned to a
ListBox ?

Any further assistance you may be able to provide would be much
appreciated.

Yours sincerely,

Brent McIntyre
 
Cor,

Thanks for that it is exactly what I was after !

Yours sincerely,

Brent McIntyre
 
* Brent McIntyre said:
FileSystemObject routines seem to be the same in VB.Net for everything I
have used thus far, except this one, the solution that Herfried provided
seemed a bit in depth for what I am trying to do, thank you anyway it is
greatly appreciated, I am still learning though and was a bit confused,
especially by the non-english comments (I still find it hard to come to

Sorry, but it's very hard to maintain sample projects in more than one
language.
terms with the fact that newsgroups allow you to have conversations with
people from all over the world). So do you know anyway simpler to get
the names of all text (or other) files in a directory returned to a
ListBox ?

\\\
ListBox1.Items.AddRange(System.IO.Directory.GetFiles("C:\Foo", "*.txt"))
///

You can loop though the array and use 'System.IO.Path.GetFileName' to
add the filenames only.
 
Brent,
You could always cut & paste the comments into Google's Language Tools (or
other translation service).

http://www.google.com/language_tools?hl=en

You could possible cut & paste the entire sample, however I'm not sure what
it would do to the program itself.

Hope this helps
Jay
 
Back
Top