473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Compressing folders in Windows using Python.

Hi,
I'm trying to zip a particular fiolder and place the zipped folder into
a target folder using python. I have used the following command in
'ubuntu'.

zip_command = 'zip -qr %s %s' % (target, ' '.join(source))

I execute this using os.command(zip_command). It works fine...

But when I run this script in Windows XP, I get an error while
executing the above zip command. What command is there to zip files in
Windows? Or is there any other problem ?

Jan 1 '06 #1
6 2068
On Sun, 01 Jan 2006 04:07:11 -0800, sri2097 wrote:
Hi,
I'm trying to zip a particular fiolder and place the zipped folder into
a target folder using python. I have used the following command in
'ubuntu'.

zip_command = 'zip -qr %s %s' % (target, ' '.join(source))

I execute this using os.command(zip_command). It works fine...

But when I run this script in Windows XP, I get an error while
executing the above zip command.
Would you like to tell us what error you get?

No no, I'll just guess... your disk is full... am I close?

*wink*
What command is there to zip files in Windows? Or is there any other problem ?


What happens if you call up a Windows command prompt and type zip at the
prompt?

--
Steven.

Jan 1 '06 #2
Steven D'Aprano wrote:
But when I run this script in Windows XP, I get an error while
executing the above zip command.


Would you like to tell us what error you get?


I presume the error he's seeing is something along the line of:

"zip: Bad command or filename."

That's basically because there is no commandline builtin for zipping up
files on Windows, and I don't know of WinZIP or any of the InfoZIP derived
GUIs installing a command-line zipper.

What might help you though (and keep you platform-independent):

http://www.python.org/doc/2.4.2/lib/module-zipfile.html

--- Heiko.
Jan 1 '06 #3
Heiko Wundram wrote:
That's basically because there is no commandline builtin for zipping up
files on Windows, and I don't know of WinZIP or any of the InfoZIP derived
GUIs installing a command-line zipper.


btw. the zip command isn't builtin on Unix either. It's only available if
you installed the corresponding InfoZIP package(s). I know pretty much
every Linux-distribution comes preinstalled with it (because of stuff like
ark, a KDE-frontend for archivers, requiring it), but you shouldn't rely on
that either.

--- Heiko.
Jan 1 '06 #4
Heiko Wundram wrote:
Steven D'Aprano wrote:
But when I run this script in Windows XP, I get an error while
executing the above zip command.


Would you like to tell us what error you get?

I presume the error he's seeing is something along the line of:

"zip: Bad command or filename."

That's basically because there is no commandline builtin for zipping up
files on Windows, and I don't know of WinZIP or any of the InfoZIP derived
GUIs installing a command-line zipper.

What might help you though (and keep you platform-independent):

http://www.python.org/doc/2.4.2/lib/module-zipfile.html

--- Heiko.


Go and get something like 7-ZIP and put a path environment variable in.
Jan 1 '06 #5
sri2097 wrote:
Hi,
I'm trying to zip a particular fiolder and place the zipped folder into
a target folder using python. I have used the following command in
'ubuntu'.

zip_command = 'zip -qr %s %s' % (target, ' '.join(source))

I execute this using os.command(zip_command). It works fine...

But when I run this script in Windows XP, I get an error while
executing the above zip command. What command is there to zip files in
Windows? Or is there any other problem ?


zip is not a built-in command for windows.
You might use winzip or something else, there is
a bunch of different compression tools available.

ciao - chris

--
Christian Tismer :^) <mailto:ti****@stackless.com>
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
Jan 1 '06 #6

Christian Tismer wrote:
sri2097 wrote:
Hi,
I'm trying to zip a particular fiolder and place the zipped folder into
a target folder using python. I have used the following command in
'ubuntu'.

zip_command = 'zip -qr %s %s' % (target, ' '.join(source))

I execute this using os.command(zip_command). It works fine...

But when I run this script in Windows XP, I get an error while
executing the above zip command. What command is there to zip files in
Windows? Or is there any other problem ?
zip is not a built-in command for windows.
You might use winzip or something else, there is
a bunch of different compression tools available.

ciao - chris


Something else to watch for -- Spaces in filenames. Uncommon on
unix/linux, but very common on windows. Put some double-quotes around
the filenames in your zip_command:

zip_command = 'zip -qr "%s" "%s"' % (target, ' '.join(source))
AFAIK there are built-in zip modules available in Python? They might be
a better alternative to calling an external zip command?

(Winzip btw, has a seperate download for a command-line capable version
of the compressor)

cheers,

--Tim

--
Christian Tismer :^) <mailto:ti****@stackless.com>
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/


Jan 1 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob | last post by:
Hi, I'm new to Python and I want to create a script that will import contactitems into an Outlook Public Folder. Therefore I've installed the Python for Windows Extensions. This way I can...
4
by: sri2097 | last post by:
Hi all,This is in reply to the 'Compressing folders in Windows using Python' query I raised y'day. I figured out that windows does not allow command line zipping so I started looking for...
3
by: msankardas | last post by:
Hi, As a part of my project, i need to compress folders and files into a single zip file as follows. for eg: I want to compress C:\test\ c:\compression\ C:\documents\test.txt
2
by: bearophileHUGS | last post by:
Helmut Jarausch: Asking in comp.compression is a good starting point. My suggestions (sorry if they look a bit unsorted): it depends on what language you want to use, how much you want to...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.