Solved

VB.NET 2005 and Searching Windows File System

Posted on 2006-07-17
5
192 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 50 total points
ID: 17121738
0
 
LVL 63

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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