Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching an entire hard drive for a file

Status
Not open for further replies.

kyledunn

Programmer
Jan 2, 2001
145
US
Anyone have the code worked out to scan every file in every directory on a hard drive to locate a single file possibly using DirectoryInfo and FileInfo?

Kyle

Hey Jack, this was really just an excuse to say hello and of course it's always possible that you will have the answer to my question. :) I am deep into windows forms desktop application development and it doesn't look like I'll return to ASP.NET anytime soon but I'm having a great time and hope all is well with you.
 
KYLE!

How's it going buddy? Glad to hear the desktop world is treating you well. I'd love to get my feet wet with the desktop side of VB.NET, and if I want to get my MCAD or MCSD, it looks like I'll have to. The next project for us after this web app is going to possibly be a desktop accounting program, so hopefully I'll be able to gleam some experience from that.

As to your question, I havn't done anything like that but I did find a post with code that appears to do what you need.


Let me know if it worked out for ya

Take Care
:)

Jack
 
Jack,

Here's what I learned. The Common Information Model (CIM) is part of the Windows Management Instrumentation (WMI) architecture. The CIM defines objects in the managed environment through classes. These classes include methods to describe behavior and properties to describe data. Some objects included in the CIM are applications, networks, printers, and drivers.

The CIM repository is an object database where defined objects — such as static class definitions and instances that are used to access and manipulate system management information — are stored.

A query can be run against the CIM Object Manager (CIMOM).

So here is a solution that works very well. Sorry it's in C# but at least you'll get some translating practice. By the way, desktop apps can only be written in C#. Just kidding.

Kyle

using System.Management;

string drive = "\"c:\"";
string filename = "\"test\"" ;
string extension = "\"exe\"";
string qry = String.Format( "select * from cim_logicalfile where drive={0} and filename={1} and extension={2}", drive, filename, extension); ManagementObjectSearcher query = new ManagementObjectSearcher(qry); ManagementObjectCollection queryCollection = query.Get(); foreach(ManagementObject mo in queryCollection) {
Console.WriteLine( "Name '{0}' :path: '{1}' ",mo["Name"], mo["Path"]); }

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top