473,795 Members | 3,215 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a folder compressed

Hello.

I am trying to make a folder compressed and failing miserably. Below
are three ways that I tried to make it compressed, all of them compile
and run w/o any problems, but the folder is still not-compressed.
(using NTFS, win2k)

// some folder
string path = @"C:\TEMP\";

// try #1
File.SetAttribu tes(path, FileAttributes. Compressed);

// try #2
File.SetAttribu tes(path, File.GetAttribu tes(path) |
FileAttributes. Compressed);

// try #3
DirectoryInfo di = new DirectoryInfo(p ath);
di.Attributes = di.Attributes | FileAttributes. Compressed;

What am I doing wrong?
(I did not work before with the FlagsAttribute enums, so I could be
doing something completely wrong, but I tried to find how to do it, and
those seem to be the proper ways)

Thanks,

Pavel

Nov 16 '05 #1
4 14121

"Pavel" <ea**********@g mail.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Hello.

I am trying to make a folder compressed and failing miserably. Below
are three ways that I tried to make it compressed, all of them compile
and run w/o any problems, but the folder is still not-compressed.
(using NTFS, win2k)

// some folder
string path = @"C:\TEMP\";

// try #1
File.SetAttribu tes(path, FileAttributes. Compressed);

// try #2
File.SetAttribu tes(path, File.GetAttribu tes(path) |
FileAttributes. Compressed);

// try #3
DirectoryInfo di = new DirectoryInfo(p ath);
di.Attributes = di.Attributes | FileAttributes. Compressed;

What am I doing wrong?


Nothing, you can't set this attribute using Directory.Attri butes you can
only get the attribute.
The documentation should indicate which attributes can be set and which
cannot but fails to do so.
Here are those that can't be set.
Directory, Encrypted, Compressed, ReparsePoint, SparseFile, OffLine and
Temporary.
All others can be set.

You can use the System.Manageme nt and the WMI class win32_directory to
compress a folder.

string dirName = "c:\\\\someFold er";
string objPath = "Win32_Director y.Name=" + "\"" + dirName + "\"";
using (ManagementObje ct dir= new ManagementObjec t(objPath))
{
ManagementBaseO bject outParams = dir.InvokeMetho d("Compress", null,
null);
uint ret = (uint)(outParam s.Properties["ReturnValu e"].Value);
if(ret == 0)
Console.WriteLi ne("Success");
else Console.WriteLi ne("Failed with error code: {0}", ret);
}

Willy.
Nov 16 '05 #2
I believe you cannot set a file attribute to be compressed, it's a property
that is readonly. For example, a text file would not be compressed, where as
a Zip file would be.

If you want to compress code, then you have to manually zip it up, then
remove the folder.

See this: http://www.icsharpcode.net/OpenSourc...b/Default.aspx

Good luck.
Dan.

"Pavel" <ea**********@g mail.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com...
Hello.

I am trying to make a folder compressed and failing miserably. Below
are three ways that I tried to make it compressed, all of them compile
and run w/o any problems, but the folder is still not-compressed.
(using NTFS, win2k)

// some folder
string path = @"C:\TEMP\";

// try #1
File.SetAttribu tes(path, FileAttributes. Compressed);

// try #2
File.SetAttribu tes(path, File.GetAttribu tes(path) |
FileAttributes. Compressed);

// try #3
DirectoryInfo di = new DirectoryInfo(p ath);
di.Attributes = di.Attributes | FileAttributes. Compressed;

What am I doing wrong?
(I did not work before with the FlagsAttribute enums, so I could be
doing something completely wrong, but I tried to find how to do it, and
those seem to be the proper ways)

Thanks,

Pavel

Nov 16 '05 #3
Thanx for your reply Willy. The code worked for me, I am currently
running a test to see whether there is a benefit (for my program) to
compress the folder.

pavel

Nov 16 '05 #4
Well, you can always un-compress :-) using the uncompress command:

ManagementBaseO bject outParams = dir.InvokeMetho d("Uncompress ", null,
null);

Willy.

"Pavel" <ea**********@g mail.com> wrote in message
news:11******** **************@ o13g2000cwo.goo glegroups.com.. .
Thanx for your reply Willy. The code worked for me, I am currently
running a test to see whether there is a benefit (for my program) to
compress the folder.

pavel

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3397
by: Roland Hall | last post by:
It appears what I'm reading is that Windows 2K3, like XP, supports what MSFT calls a compressed zipped folder. Is this exposed so I can effectively use FSO or a shell to create one of these and move some files into it and then offer it as a download on my web site? -- Roland Hall /* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or...
0
393
by: Vladimir Nesterovsky | last post by:
Hello, I'm having a trouble with a Shell.Folder object when I'm trying to use it from a C++ application, but at the same time, the same object works fine from within html script. The effect is that, I cannot put data into a compressed folder in C++, in spite of the fact that all operations succeed. Note: all this have to work under XP and above, because of integrated
3
5969
by: Justin Busch | last post by:
I thought I saw an article online about programmatically using the Send To Compressed (zipped) Folder function in VB, however that page no longer exists. Does anyone have details on how this is possible? Justin Busch jbusch@ccac.edu
2
1963
by: CK | last post by:
One way to save storage space is to put the SQL data files into a compressed file. Has anyone got any idea how this will affect the query speed?
5
1996
by: _DG | last post by:
At least when you've got any docs in .CHM format in the folder tree. If you drop a file called CSharpDocs.chm into a folder: \toplevel\C#\docs, you can open it, but it won't display. The # anywhere in the folder hierarchy is enough to cause problems. I spent quite a while trying to figure this out. Tried it on several systems. Even discarded some CHM files, thinking they were corrupt. This is evidently a problem with Microsoft's own...
1
1759
by: Phil Haddock | last post by:
Can anyone post a code snippet on how to retrieve Permission information on a Folder? (Visual Basic 2005) There's lot's of information on how to set a permission, but I can't figure out how to read them. I want to be able to return what Users and Groups have what permissions on the folder. I'm not interested in the files within, although I know that they may vary from the folder itself. Thanks,
2
3867
by: mravichandran | last post by:
dear Readers, i will be downloading a zip file from the intranet website programmatically and i would like to process some of the files inside them before the user can save it. we have a lot of copies of winzip. winzip does not let me call their functions as COM or as .NET assemblies. I want to use the native compressed folder function present in the Windows XP OS to open the zip file and process them before the user can
2
3740
by: steggun | last post by:
Hello, I'm writing a C# windows form application and need some guidance on a couple of issues. First, my application needs to change the permissions on a folder. The application creates a local group and I need to give that group Full Control permissions to a folder on the file system. Would anyone know how to accomplish this?
1
1609
by: =?Utf-8?B?S2V5QmVl?= | last post by:
- YOU CAN PROTECT ZIPPED COMPRESSED FOLDER WITH A PASSWORD (PW). - YOU MUST PROVIDE THE PW BEFORE THE FILE CAN BE EXTRACTED. - HOW CAN YOU EXTRACT THE FILE IF YOU FORGOT THE PW ?
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.