File Compression Using a .bat

OliG Posted messages 4 Status Membre -  
BlueskyFR Posted messages 76 Status Membre -
Hello,

I am looking for an example of a batch file that creates a .zip from a .bat. This must be executed automatically after a C++ compilation in Visual Studio 2005, so it is not possible to manually compress the files. I need to include files that are in different directories into a single .zip.

Does Windows have a default "zip" command? I need to send this project via email, and I need to be sure that the .bat will work on the recipient's machine... so I can't use some obscure program, no matter how effective it is. What are my options?

So far, I have tried the "zip" command but I get an error: 'zip' is not recognized as an internal or external command, an executable program or a batch file.

Any help would be appreciated,
Thank you!
Configuration: Windows Vista Firefox

19 réponses

dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
hello
I'm using the free 7-zip: https://www.7-zip.org/
in the help section, there are all the options to run it from the command line, so in .bat:
Commands quick reference Command Description a Add d Delete e Extract l List t Test u Update x eXtract with full paths 
8
OliG Posted messages 4 Status Membre 10
 
Wow! I didn't expect that!

I know very well that Winzip is commercial... I don't use Winzip, that's all...
By the way, where does this brutal remark about Winzip come from? From the command "zip"? I mentioned this since a friend, wanting to help me, gave me a short example that included this command... The trouble is that I can't use it at home (maybe precisely because I don't have Winzip?), the compiler returns an error (as mentioned above): "zip" is not recognized as an internal or external command, an executable program, or a batch file. My question remains: is there a default command that allows zipping files on any computer?

Please be lenient if there are any oddities in my question, the truth is that I've never done a batch file... I've searched the internet but I haven't found anything conclusive on compression batch files (except for pkzip, but I can't use that). That's precisely why I'm asking for your help on this matter.

If you think about making a personal attack against me without bringing anything constructive to my problem... please kindly leave without causing a ruckus (like you, Phil)

If you can help me or simply direct me to a website that I've missed, I would greatly appreciate it.
Thank you.
7
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
7z a -tzip archive.zip F:\Mesdocs\*
5
OliG Posted messages 4 Status Membre 10
 
I don't see what's so terrible about my question, can someone explain it to me?

If no compression program is installed, Windows supports decompressing files... Is it so dumb to ask if there is a console command for this operation?

I ended up including 7za.exe in my folder (a "stand alone" version of 7z)...
3
OliG Posted messages 4 Status Membre 10
 
Thank you, dubcek!

I tried using 7-zip and it works very well.
The only grain of sand in the gears is that if the recipient of my project doesn't have the 7-zip program on their computer, they won't be able to compile. That's why I wanted to know if there is a default Windows command for compression.

In truth, by "obscure program," I was referring to info-zip, a free compression utility that works as well but doesn't seem very well known. For now, I will simply indicate or download 7-zip.

Out of personal curiosity, for next time, does anyone know if there is a Windows-specific compression command?

Thanks again, dubcek!
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
If I understand the question correctly, the goal is to have an open-source C++ program that creates or reads a .zip file?
0
phil_232 Posted messages 286 Status Membre 33
 
WinZip still exists in trial mode, meaning there is a free version.

https://www.winzip.com/win/en/
0
rodrigue62 Posted messages 201 Status Membre 30
 
Hello,

I need your help, hoping not to be insulted because my question will be "stupid."
7Zip is installed on my PC, but when I type 7z at the command prompt, it responds: "'7Z' is not recognized as an internal or external command..."
Where is my mistake? I saw this command in the Help file of 7 Zip, isn't that how it is used?

Thank you in advance.
0
logon313 Posted messages 50 Status Membre 9
 
Hello!
I made a careless mistake that you might have made too:
the external file is called "7za.exe" and you probably typed the command "7z"
0
BlueskyFR Posted messages 76 Status Membre 9 > logon313 Posted messages 50 Status Membre
 
This response is 6 years old... :D The problem has probably been solved or they've moved on since then ;)
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
You must specify the full path, with quotes due to spaces

C:>"C:\Program Files\7-Zip\7z"

7-Zip 4.42 Copyright (c) 1999-2006 Igor Pavlov 2006-05-14

Usage: 7z <command> [<switches>...] <archive_name> [<file_names>...]
[<@listfiles...>]

<Commands>
a: Add files to archive
d: Delete files from archive
...
...
0
rodrigue62 Posted messages 201 Status Membre 30
 
Thank you for your help.
I'm making progress, but now I'm getting the message "incorrect wildcard in listfile" and it's not very clear to me.
0
rodrigue62 Posted messages 201 Status Membre 30
 
Can anyone help me with the error message I'm getting?

Thank you in advance.
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
show the command used
0
rodrigue62 Posted messages 201 Status Membre 30
 
<img src="http://img1.imagilive.com/0109/7zerror.gif">
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
les " sont inutiles s'il n'y a pas d'espace dans les noms
l'erreur est dans le fichier F:\Mesdocs

List file
You can supply one or more filenames or wildcards for special list files (files containing lists of files). The filenames in such list file must be separated by new line symbol(s).

For list files, 7-Zip uses UTF-8 encoding by default. You can change encoding using -scs switch.

Multiple list files are supported.

For example, if the contents of file "listfile.txt" are the following:

My programs\*.cpp
Src\*.cpp

then command

7z a -tzip archive.zip @listfile.txt

adds to archive "archive.zip" all "*.cpp" files from directories "My programs" and "Src".

0
rodrigue62 Posted messages 201 Status Membre 30
 
If I want to compress the entire folder F:\Mesdocs, do I still need to go through a listfile.txt in which I would write only F:\Mesdocs?
0
dubcek Posted messages 18702 Registration date   Status Contributeur Last intervention   5 657
 
No, no need for a file, a listfile is for varied and complex paths.
0
rodrigue62 Posted messages 201 Status Membre 30
 
So what's the problem when I want to compress F:\Mesdocs, the path name isn't detailed enough?
Thank you for your help.
0
rodrigue62 Posted messages 201 Status Membre 30
 
impeccable. Thank you very much.
0
arth Posted messages 84 Registration date   Status Contributeur Last intervention   1 293
 
Did you expect Windows to make coffee too, or did you leave that solution to your coffee maker?
--

The wolf, solitary and mysterious.
-9
phil_232 Posted messages 286 Status Membre 33
 
You program in C++ and you don't know that WinZip is a commercial program in the meantime????
I doubt your abilities
Otherwise, it's with Shell that we do that.
-11