?
Solved

VB.NET 2005 and Searching Windows File System

Posted on 2006-07-17
5
Medium Priority
?
198 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
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 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