472,782 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Zipping files

Hi all,

I have come across an error while using zipfile and I can't seem to
find somewhere that explains the problem. My script needs to be able
to take text files from one drive and add them to zip files on another
drive. The following seems to work just fine.

import zipfile

# write test file in working directory directory
folder = "J:/"
filename = "testing.txt"
fullpath = folder+filename
fout = open(fullpath, 'wt')
fout.write(str1)
fout.close()

# Add text file to zip file on same drive
zFolder = "J:/"
zFilename = "testing.zip"
zFullpath = zFolder+zFilename
zout = zipfile.ZipFile(zFullpath, "w")
zout.write(fullpath)
zout.close()
print fullpath, "successfully added to", zFullpath

However, if I change the drive letters to anything other than the
drive from which the Python script is saved (e.g. run script from J:
but zip to C:), I get the following warning:

Traceback (most recent call last):
File "J:/test.py", line 18, in <module>
zout = zipfile.ZipFile(zFullpath, "w")
File "C:\Python25\lib\zipfile.py", line 339, in __init__
self.fp = open(file, modeDict[mode])
IOError: [Errno 13] Permission denied: 'C:/testing.zip'

Can anyopne shed some light on what I am missing here? If it has any
relevance to the permissions part of the error, I am currently using
Windows machines.

Thanks in advance for your time.

Dan

Jul 15 '08 #1
3 4263
dp_pearce wrote:
Hi all,

I have come across an error while using zipfile and I can't seem to
find somewhere that explains the problem. My script needs to be able
to take text files from one drive and add them to zip files on another
drive. The following seems to work just fine.

import zipfile

# write test file in working directory directory
folder = "J:/"
filename = "testing.txt"
fullpath = folder+filename
fout = open(fullpath, 'wt')
fout.write(str1)
fout.close()

# Add text file to zip file on same drive
zFolder = "J:/"
zFilename = "testing.zip"
zFullpath = zFolder+zFilename
zout = zipfile.ZipFile(zFullpath, "w")
zout.write(fullpath)
zout.close()
print fullpath, "successfully added to", zFullpath

However, if I change the drive letters to anything other than the
drive from which the Python script is saved (e.g. run script from J:
but zip to C:), I get the following warning:

Traceback (most recent call last):
File "J:/test.py", line 18, in <module>
zout = zipfile.ZipFile(zFullpath, "w")
File "C:\Python25\lib\zipfile.py", line 339, in __init__
self.fp = open(file, modeDict[mode])
IOError: [Errno 13] Permission denied: 'C:/testing.zip'

Can anyopne shed some light on what I am missing here? If it has any
relevance to the permissions part of the error, I am currently using
Windows machines.

Is it possible that you don't in fact have permission
to write to c:\? I seem to recall that non-power-users
on XP don't have that permission, and I bet that Vista
makes that even more restrictive.

TJG
Jul 15 '08 #2
When I saw "Permission denied", this was my suspicion. And I think you
are very right. I have just gone back and tried writing to a file
outside of C:, in this case C:/output/, and it seems to work again.

Would I be right in guessing there is no way around this?

Dan
Jul 15 '08 #3
dp_pearce wrote:
When I saw "Permission denied", this was my suspicion. And I think you
are very right. I have just gone back and tried writing to a file
outside of C:, in this case C:/output/, and it seems to work again.

Would I be right in guessing there is no way around this?
Well, you could (presumably) alter your own user's
groups / rights and/or the permissions on the root
of the C: drive so that you *can* zip to that location.

On the other hand, chucking random stuff into the
root of the system drive has never been considered
a brilliant idea. (Altho' I know a lot of people
who do it :) ). Why not create a suitable folder
lower down, or in your own %APPDATA% area, or using
the tempfile module, depending on your needs?

TJG
Jul 15 '08 #4

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

Similar topics

2
by: Arthur | last post by:
Does anyone know if the new Windows 2003 built-in .zip compressor/decompressor is available to scripting? If so, can you kindly point me in the right direction? I've searched and searched MSDN...
2
by: Beau | last post by:
Is there a native 'zipping' or compression compoonent in windows accessable via ASP? Or do you have to buy a compoonent?
0
by: Benjamin Bittner | last post by:
hallo ng, first of all, for the zipping progress i use the ziplib from http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx now to my problem. im trying to build a little application...
1
by: RJN | last post by:
Hi Does .Net provide libraries for zipping files? I read that a third party component CSharplib is available for doing this. Is there any license restriction for using this? Thanks rjn
9
by: ReidarT | last post by:
How can I zip (compress) a file in vs2005 with windows own zip-program? reidarT
6
by: reidarT | last post by:
I will develop a backup routine with local files (zipped) to an internet server via ftp. How do I zip files in Vb.net? reidarT
7
by: Dylan Parry | last post by:
Hi folks, I've got a page that outputs XML, but in some cases the size of the page is several MB. So I figured the best way to deal with it is to ZIP the contents of the page and send that to...
1
by: durumdara | last post by:
Hi! As I experienced in the year 2006, the Python's zip module is not unicode-safe. With the hungarian filenames I got wrong result. I need to convert iso-8859-2 to cp852 chset to get good...
2
by: karen.google | last post by:
I have an SSIS package that I'm converting from DTS (SQLServer 2005), and the ActiveX Script Task (in VBScript) is deprecated, so I'm trying to convert things to Script tasks (in VB .net). I...
2
by: Alien | last post by:
Hi, I am fairly new to PHP and wondering if there if PHP has any library that does zipping of files. Cheers.
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.