 |

06-07-2006, 03:41 AM
|
|
Newcomer
|
|
Join Date: Nov 2002
Location: Stockholm
Posts: 23
|
|
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!
|
|

06-07-2006, 08:06 AM
|
 |
Centurion
|
|
Join Date: Oct 2003
Location: London, England.
Posts: 151
|
|
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.
|
|

06-07-2006, 08:14 AM
|
|
Newcomer
|
|
Join Date: Nov 2002
Location: Stockholm
Posts: 23
|
|
|
|
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?
|
|

06-13-2006, 01:46 AM
|
 |
Centurion
|
|
Join Date: Jul 2004
Location: Arlington, Texas
Posts: 189
|
|
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 02:00 AM.
|

06-13-2006, 02:45 AM
|
|
Newcomer
|
|
Join Date: Nov 2002
Location: Stockholm
Posts: 23
|
|
Thank you! That worked perfect!
|
|

06-13-2006, 09:01 AM
|
|
Freshman
|
|
Join Date: Jan 2006
Posts: 34
|
|
kungbengan ... can you post the code that worked for you? Thanks...
|
|

06-13-2006, 09:07 AM
|
|
Newcomer
|
|
Join Date: Nov 2002
Location: Stockholm
Posts: 23
|
|
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
|
|

06-13-2006, 11:53 AM
|
|
Freshman
|
|
Join Date: Jan 2006
Posts: 34
|
|
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?
|
|

06-13-2006, 01:42 PM
|
|
Freshman
|
|
Join Date: Jan 2006
Posts: 34
|
|
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
|
|

06-14-2006, 12:18 AM
|
|
Newcomer
|
|
Join Date: Nov 2002
Location: Stockholm
Posts: 23
|
|
How do I get this to work?
My.Computer.FileSystem.WriteAllBytes(dstfolderString, fileContents, False)
|
|

06-14-2006, 05:52 AM
|
|
Freshman
|
|
Join Date: Jan 2006
Posts: 34
|
|
This works in VB 2005 Express. Perhaps you are using an older version of VB?
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
| |
|