?
Solved

VB.NET 2005 and Searching Windows File System

Posted on 2006-07-17
5
Medium Priority
?
196 Views
Last Modified: 2010-04-23
I am new to VB.Net 2005 and recently bought a book and am going through it to learn the language.  However one topic which I expect to need to know isn't covered in the book, which is searching for files.  Can someone point me to a book,website, article that includes sample code and good instructions for searching for files?  Thanks.
0
Comment
Question by:jibip
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17121480
Hi jibip,

Do you mean searching in code?

Apresto
0
 
LVL 23

Expert Comment

by:apresto
ID: 17121496
If so just look up the System.Io Namespace and make sure your proficient in Looping and your well away,

Some useful classes you may need are:

Dictionary
DictionaryInfo
File
FileInfo

However i will find some useful references for you
0
 

Author Comment

by:jibip
ID: 17121678
apresto,

Yes I mean programmatically searching for files based on name, date created, etc, using wildcards, etc.
0
 
LVL 23

Accepted Solution

by:
apresto earned 150 total points
ID: 17121738
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17122451
Hi jibip;

In Visual Basic 2005 Microsoft added a ne method to the DirectoryInfo class called GetFiles(searchPattern, CurrentDirectory Or CurrentDirectoryAndAllSubDirectories)

The searchPattern from the documentation:
Wildcards are permitted. For example, the searchPattern string "*.txt" searches for all file names having an extension of "txt". The searchPattern string "s*" searches for all file names beginning with the letter "s". If there are no files, or no files that match the searchPattern string in the DirectoryInfo, this method returns an empty array.

The matching behavior of searchPattern when the extension is exactly three characters long is different from when the extension is more than three characters long. A searchPattern of exactly three characters returns files having an extension of three or more characters. A searchPattern of one, two, or more than three characters returns only files having extensions of exactly that length.

Link to Documentation:
http://msdn2.microsoft.com/en-us/library/ms143327.aspx

Imports System.IO

        Dim di As New DirectoryInfo("C:\temp")
        Dim fi() As FileInfo = di.GetFiles("c*.vb", SearchOption.AllDirectories)

The above code will return a FileInfo class for each file that it finds that starts with a s and has the extension .vb into the array fi. Once you have the array of FileInfo you can find the FullName of the file File Creation Date, Attributes, Creation Time  and others. This is the link to the documentation for the FileInfo class and what info it holds.


http://msdn2.microsoft.com/en-us/library/system.io.fileinfo_members.aspx

Fernando
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question