Page 1 of 2
Batch File to Compress File Using Windows
Posted: 01 Nov 2012 09:24
by accesshawaii
The computer that I am on, I cannot download Winzip or 7Z etc. I have to work with what I have. I have the regular Windows default right click on a file and select "Send to Compressed Zip Folder"
If I have a file called MyTest.XLS located in C:\MyFolder and I want it to zip to C:\MyZips, how would I do that? I have some knowledge of batch files but by no means an expert. Any assistance would be appreciated.
Re: Batch File to Compress File Using Windows
Posted: 01 Nov 2012 10:16
by accesshawaii
Ok, I was able to get 7-Zip installed. Could someone help me with the syntax for zipping the file that I outlined in the first post using 7-zip? Thanks.
Re: Batch File to Compress File Using Windows
Posted: 01 Nov 2012 11:08
by Boombox
.
7z <command> [<switches>...] <archive_name> [<file_names>...]
Code: Select all
7z a -t 7z -r "c:\backup.7z" "c:\MyStuff\*.*"
(
Adds to -
type
7zip archive -
Recursively Save to
"c:\backup.7z" All from
"c:\Mystuff\*.*")
Remember to use " " quotes if the destination has spaces in it!
http://www.dotnetperls.com/7-zip-examplesType 7zip /? at CMD for help (at a guess)
Re: Batch File to Compress File Using Windows
Posted: 01 Nov 2012 11:28
by accesshawaii
Thanks for the reply but that did not work. I even made a folder called "backup" and one called "MyStuff", which I placed files in both and nothing happened. I'm assuming that backup is where the files would be placed and MyStuff is where the files are coming from. Below is the exact syntax that I used.
7z a -t 7z -r "C:\backup.7z" "c:\MyStuff\*.*"
Any suggestions?
Re: Batch File to Compress File Using Windows
Posted: 01 Nov 2012 11:42
by Boombox
.
EDITED
-t7z instead of -t 7z
NO SPACE!
Re: Batch File to Compress File Using Windows
Posted: 01 Nov 2012 12:02
by accesshawaii
I appreciate your patience with this but it's still not working. Below is what I'm using.
7z a -t7z -r "c:\backup.7z" "c:\MyStuff\*.*"
Re: Batch File to Compress File Using Windows
Posted: 01 Nov 2012 12:14
by Boombox
.
I copied the code above, into CMD after creating the MyStuff folder on c:
Everything went ok
Where and when did you get your version?
What error message do you get?
Backup.7z is the archive name,
MyStuff\*.* is everything inside MyStuff folder including sub-directories
Make sure 't7z and Backup.7z are the same.
Re: Batch File to Compress File Using Windows
Posted: 02 Nov 2012 04:36
by accesshawaii
When I paste the below in a dos command prompt
7z a -t7z -r "c:\backup.7z" "c:\MyStuff\*.*"
I get the error
'7z' is not recognized as an internal or external command, operable program, or batch file
I'm running 7-Zip 9.20. I just downloaded it yesterday.
Re: Batch File to Compress File Using Windows
Posted: 02 Nov 2012 04:59
by foxidrive
You need to include the path to the executable. Assuming it is located in "c:\Program Files\7-Zip\" then try this:
Code: Select all
"c:\Program Files\7-Zip\7z.exe" a -t7z -r "c:\backup.7z" "c:\MyStuff\*.*"
Re: Batch File to Compress File Using Windows
Posted: 02 Nov 2012 05:04
by Boombox
.
I can go straight to CMD, type 7z (on its own), press enter and get a response...
You many need to reinstall...
Can you find the 7zip folder?
Re: Batch File to Compress File Using Windows
Posted: 02 Nov 2012 05:33
by alan_b
Boombox wrote:.
You many need to reinstall...
NOT true if the Portable version of 7z was used.
Foxidrive's solution will always work so long as you correctly stipulate the path.
Re: Batch File to Compress File Using Windows
Posted: 02 Nov 2012 19:30
by miskox
Why don't you use a standalone zip.exe? You can just put it somewhere in your path.
Here
http://www.info-zip.org/Zip.html you can get it. It works on XP, I don't have Win7 to test it. It probably works.
Saso
Re: Batch File to Compress File Using Windows
Posted: 02 Nov 2012 22:16
by foxidrive
7-zip can handle more files in a ZIP than ZIP can.
7-zip also has the capability to make ZIP archives.
7-zip has superior compression compared to ZIP
Re: Batch File to Compress File Using Windows
Posted: 03 Nov 2012 03:29
by Ed Dyreen
'
7-Zip 4.57 Console ( Igor Pavlov ) can unpack .ISO images
Re: Batch File to Compress File Using Windows
Posted: 05 Nov 2012 09:08
by accesshawaii
foxidrive,
What you posted worked!!!. Thanks. Thanks to everyone for the responses.
Ready for another brain teaser? What I'm actually trying to do is create a back-up of a file each month. The name of the zip will need to have the date that it was backed up and the abbreviation of the previous month. So, if I did a back-up today, it would look something like below.
20121105_Oct_Data.7z
I know I can get the date portion by doing something like
"c:\Program Files\7-Zip\7z.exe" a -t7z -r "c:\%date:~10,4%%date:~4,2%%date:~7,2%_MyBackup.7z" "c:\MyStuff\*.*"
My question is how could I get the actual name of the previous month, so it would display as the example I gave above? Any assistance would be appreciated.