Solved

VB.NET 2005 and Searching Windows File System

Posted on 2006-07-17
5
191 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 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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