And of course you can call Delete on the   ManagementObject to delete the files like:

queryCollection = query.Get();
   foreach( ManagementObject dataFile in queryCollection ) {
            // delete file object in the collection
            dataFile .Delete();
  }

Willy.


----- Original Message -----
From: "Blain Timberlake" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 04, 2002 8:21 PM
Subject: Re: [DOTNET] Deletion of old files....


> Very interesting....
>         Thanks for the code, I'll give that a whirl and see how it plays
> out.
>
> =Blain
>
> -----Original Message-----
> From: The DOTNET list will be retired 7/1/02
> [mailto:[EMAIL PROTECTED]] On Behalf Of Marsh, Drew
> Sent: Tuesday, June 04, 2002 2:16 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [DOTNET] Deletion of old files....
>
> Blain Timberlake [mailto:[EMAIL PROTECTED]] wrote:
>
> > Correct, and this way has been working for me, but for some
> > reason I recall seeing an example that did it in a much
> > simpler manner, but I can't find it to save my life.  Thought
> > someone else might have seen something on it.
>
> You could use System.Management (WMI), like so:
>
> <codeSnippet language="C#">
> SelectQuery query = new SelectQuery("CIM_DataFile", @"Drive='c:' AND
> Path='\\your\\path\\here\\' AND CreationDate > '6/1/02'");
>
> ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
>
> foreach(ManagementObject dataFile in searcher.Get())
> {
>   Debug.WriteLine(String.Format("{0}:{1}", dataFile["Name"],
> dataFile["CreationDate"]));
> }
> </codeSnippet>
>
> Note: I'm using a literal string for the filter, but you need to escape
> path
> quotes at the WMI query level. So if you weren't using a literal string
> you'd have to have to have "\\\\" for every path separator.
>
> I'd bet that WMI is doing the same looping logic as you would be once it
> gets to the specified directory. So while this makes for a lot
> cleaner/clearer source code, it probably adds a lot of undue overhead.
> It's
> up to you to do some performance test and find out what makes the most
> sense
> for you.
>
> HTH,
> Drew
> .NET MVP
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET,
> or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>
> You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to