How to programmatically set the "compress" attribute of a folder with C#

  • Thread starter Thread starter delphiconsultingguy
  • Start date Start date
Anybody?

thanks,
Sean

Very easy, use System.Management and WMI's class Win32_Directory method
Compress.
Here's a sample....

using System.Management;
....
string dirName = "c:\\\\somefolder";
string objPath = "Win32_Directory.Name=" + "\"" + dirName + "\"";
Console.WriteLine(objPath);
using (ManagementObject dir= new ManagementObject(objPath))
{
ManagementBaseObject outParams = dir.InvokeMethod("Compress", null,
null);
uint ret = (uint)(outParams.Properties["ReturnValue"].Value);
if(ret == 0)
Console.WriteLine("Success");
else Console.WriteLine("Failed with error code: {0}", ret);
}

Willy.
 
Back
Top