Create compressed folder
Create compressed folder
Create compressed folder
Create compressed folder
Create compressed folder
Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder
Create compressed folder Create compressed folder
Create compressed folder
Go Back  Xtreme Visual Basic Talk > > > Create compressed folder


Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2006, 04:41 AM
kungbengan kungbengan is offline
Newcomer
 
Join Date: Nov 2002
Location: Stockholm
Posts: 23
Default Create compressed folder


How do I create a compressed folder? I am using XP and want to use the built in zip functionality.

I am trying to do it like this:

Dim objDirectory As DirectoryInfo

objDirectory = Directory.CreateDirectory(MyDir)
objDirectory.Attributes = FileAttributes.Compressed

Thanks for the help!
Reply With Quote
  #2  
Old 06-07-2006, 09:06 AM
Teaboy's Avatar
Teaboy Teaboy is offline
Centurion
 
Join Date: Oct 2003
Location: London, England.
Posts: 151
Default

The NTFS file system has a built in compression system which is nothing to do with Zip, so you'll end up compressing it that way using that method.
Reply With Quote
  #3  
Old 06-07-2006, 09:14 AM
kungbengan kungbengan is offline
Newcomer
 
Join Date: Nov 2002
Location: Stockholm
Posts: 23
Default

I understand that, but how can I simulate in code to do an "Send to compressed folder"? Everywhere I look I just find dlls to add and I just want to add files to a compressed folder. Is that possible in an easy way?
Reply With Quote
  #4  
Old 06-13-2006, 02:46 AM
Allen G's Avatar
Allen G Allen G is offline
Centurion
 
Join Date: Jul 2004
Location: Arlington, Texas
Posts: 189
Default

Quote:
Originally Posted by kungbengan
I understand that, but how can I simulate in code to do an "Send to compressed folder"? Everywhere I look I just find dlls to add and I just want to add files to a compressed folder. Is that possible in an easy way?
I found this link, it's in C# but you shouldn't have trouble converting it to VB.

Zip files with Windows Shell API and C#

The title says "Decompress Zip files with Windows Shell API and C#". But the the article says you can compress files aswell. I assume it is included with the tutorial.

Also check out this example (it's in vb6):
Using Windows XP "Compressed Folder" shell extension to work with .zip files

Last edited by Allen G; 06-13-2006 at 03:00 AM.
Reply With Quote
  #5  
Old 06-13-2006, 03:45 AM
kungbengan kungbengan is offline
Newcomer
 
Join Date: Nov 2002
Location: Stockholm
Posts: 23
Default

Thank you! That worked perfect!
Reply With Quote
  #6  
Old 06-13-2006, 10:01 AM
nbrege nbrege is offline
Freshman
 
Join Date: Jan 2006
Posts: 34
Default

kungbengan ... can you post the code that worked for you? Thanks...
Reply With Quote
  #7  
Old 06-13-2006, 10:07 AM
kungbengan kungbengan is offline
Newcomer
 
Join Date: Nov 2002
Location: Stockholm
Posts: 23
Default

Quote:
Originally Posted by nbrege
kungbengan ... can you post the code that worked for you? Thanks...
Hi!

I really wanted to create a new zip folder also but I haven't managed to do so, but just to copy files to a zip folder this is the solution:

Dim objShell As New Shell32.ShellClass
Dim objFolderSrc As Shell32.Folder
Dim objFolderDst As Shell32.Folder
Dim objFolderItems As Shell32.FolderItems

objFolderSrc = objShell.NameSpace("C:\MyFolder")
objFolderDst = objShell.NameSpace("C:\MyCompressedFolder.zip")
objFolderItems = objFolderSrc.Items
objFolderDst.CopyHere(objFolderItems, 20)

/Bengt
Reply With Quote
  #8  
Old 06-13-2006, 12:53 PM
nbrege nbrege is offline
Freshman
 
Join Date: Jan 2006
Posts: 34
Default

OK, I got this to work for adding files to an existing compressed folder, but I would really like to be able to create a new compressed folder. Anyone have any ideas?
I can create a new folder through windows explorer by right-clicking & picking New>Compressed (zipped) Folder, but how do I do that programatically?
Reply With Quote
  #9  
Old 06-13-2006, 02:42 PM
nbrege nbrege is offline
Freshman
 
Join Date: Jan 2006
Posts: 34
Default

After doing some digging, I figured out how to create a new zip file.


Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim srcfolderString As String Dim dstfolderString As String = "c:\MyCompressedFolder.zip" 'get folder to zip Dim fbd As New FolderBrowserDialog fbd.ShowDialog() srcfolderString = fbd.SelectedPath If srcfolderString = "" Then Exit Sub 'create empty zip file Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False) Dim objShell As New Shell32.ShellClass Dim objFolderSrc As Shell32.Folder Dim objFolderDst As Shell32.Folder Dim objFolderItems As Shell32.FolderItems objFolderSrc = objShell.NameSpace(srcfolderString) objFolderDst = objShell.NameSpace(dstfolderString) objFolderItems = objFolderSrc.Items objFolderDst.CopyHere(objFolderItems, 20) End Sub
Reply With Quote
  #10  
Old 06-14-2006, 01:18 AM
kungbengan kungbengan is offline
Newcomer
 
Join Date: Nov 2002
Location: Stockholm
Posts: 23
Default

How do I get this to work?
My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
Reply With Quote
  #11  
Old 06-14-2006, 06:52 AM
nbrege nbrege is offline
Freshman
 
Join Date: Jan 2006
Posts: 34
Default

This works in VB 2005 Express. Perhaps you are using an older version of VB?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Create compressed folder
Create compressed folder
Create compressed folder Create compressed folder
Create compressed folder
Create compressed folder
Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder Create compressed folder
Create compressed folder
Create compressed folder
 
Create compressed folder
Create compressed folder
 
-->