473,770 Members | 4,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2112
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
1902
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 access my personal contacts <code> import win32com.client
4
1732
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 alternatives. I found some modules in Perl which does zipping. I guess it goes by the name 'gzip'. I plan to write the zipping feature in Perl and import it into Python.
3
3232
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
3211
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 compress the strings, if they are ASCII or unicode, how much quickly you want to compress/ decompress them, and how much time you have to write the encoder/ decoder.
0
9602
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10017
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.