Solved

VB.NET 2005 and Searching Windows File System

Posted on 2006-07-17
5
188 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
Comment Utility
Hi jibip,

Do you mean searching in code?

Apresto
0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
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
Comment Utility
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
Comment Utility
0
 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now