7zip command line problem multiple file or folder contents

Bangorgav

New member
Local time
Today, 12:37
Joined
Aug 12, 2012
Messages
9
Hi guys, trying to zip files at the click of a button in an access form, at the minute i've got it working for individual files but i can't get it to zip the entire contents of the folder in one zip folder.. Its ziping each individual txt file in its own zip file.

I'm hoping its something basic i've missed either that or im doing it completly wrong!

Here goes : -


Option Compare Database

Sub ZipFiles1()
Dim file As Variant

Const FILESOURCE = "C:\New Folder\"


Const FILEDEST = "C:\New Folder\ZIP\"


Const ZIPDIRPATH = "C:\Program Files\7-Zip\7z.exe"

For Each file In CreateObject("Scripting.FileSystemObject").GetFolder(FILESOURCE).Files
Shell ZIPDIRPATH & " a -tzip """ & FILEDEST & "\" & file.Name & ".zip"" """ & file.Path & """"
Next
End Sub
_________________________________________________________________

Thanks for your help!
 
Have you checked the command line reference for 7zip? And have you tried it via command line before calling it in VBA?
 
Can't at the minute as i'm in work. I got the information from dotnetpeals 7zip examples. which says the "a" command should put all the files within the zip folder, which makes me think the VBA code is incorrect.

Thanks Guys
 
So when you have time try it out in command prompt first before you start writing code.
 
By using using "For each" you are making a zip for each file :D

What you want doesn't require a "for each" but can simply be done with wildcards. Use a variable or hardcode the required filename like:

Code:
Shell  Chr(34) & ZIPDIRPATH & Chr(34) & " a -tzip " & Chr(34) & FILEDEST & "\" & Yourzipfilename & Chr(34) & " " & Chr(34) & FILESOURCE & "*.*" & Chr(34)

Note: changed your tripple quote to chr(34),
didn't test for trailing backslash in foldername so it probably wont work :rolleyes:
 
Do you know what PeterF, somehow I didn't even see the For loop. See why it's nice to have code in the code block, easier to read.
 
PeterF Your a gentleman and a scholar!, Thanks for all your help. the both of you!
 
Following on from this, codes working and im Zipping over 10 folders seperatly, After the files are zipped i have a button to Email the zipped files. however since the program will be used by other staff I need to have a way to let the user know when they can click the button, incase they click the email button before the files are zipped. The files will be zipped and emailed on a daily basis.

is there anyway of incorporating 7zip's progress or length of time the command line is open so once its either completed or Command line has closed itself the button for emailing will then be enabled.. Either that or a progress bar would work too..

Any suggestions would be fantastic.
 
Search for Chip Pearson's Shell and wait module on Google. His is quite good.
 
hi guys back with the same code, all the zipping is working fine, however how do i add the functionality of everytime i click the zip button it replaces the current zip files with new ones.

The zip files will be zipped everyday, with new information in the source files...
 

Users who are viewing this thread

Back
Top Bottom