[Tutor] Writing to a file problem....
Marty Pitts
mortimerp at live.com
Fri Dec 5 09:51:45 CET 2008
Hi,
I am currently working my way through the .pdf Byte of Python tutorial by Swaroop, C H
After about 1/2 way I ran into a problem that my own trouble shooting has failed :-(.
The script created is for backing up files into a .zip format. It is written by the
author in a *nix environment. However, I am currently on a *doz box. I have made certain
changes in order for it to play nice with Windows, but I am still stumped.
Here is the script:
#!c:\python26\python.exe
# Filename : backup_ver1.py
import os
import time
#1. The files and directories to be backed up are specified in a list
source = ['c:\Users\Marty\Downloads', 'c:\Users\Marty\Contacts']
#2. The backup must be stored in a main backup directory
target_dir = 'J:\\backup\\'
#3. The files are backed up into a zip file.
#4. The name of the zip archive is the current date and time
target = target_dir + time.strftime('%Y%m%d%H%M%S') + '.zip'
#5. We use the zip command to put files in a zip archive
zip_command = "c:\Users\Marty\Zip\Zip -!rv '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
print 'Sucessful backup to', target
else:
print 'Backup FAILED'
The error I get running the script from a command prompt is:
C:\Python26>backup_ver1.py
zip I/O error: Invalid argument
zip error: Could not create output file ('J:/backup/20081205002535.zip')
Backup FAILED
>From what I can tell, it might be a problem writing the file in Windows.
Maybe a rights issue. I don't know. I have tried granting the folder
all the write rights I could think of.
If I change the target_dir to just 'j:' I then get the zip program appearing
to run through all the files compressing them, but I end up with this msg:
total bytes=104598424, compressed=102594319 ->2% savings
zip warning: new zip file left as 'J:zia03824
zip I/O error: Invalid argument
zip error: Could not create output file (was replacing the original zip file)
Backup FAILED
Any suggestions would be appreciated.
Thanks,
Marty.
_________________________________________________________________
Send e-mail faster without improving your typing skills.
http://windowslive.com/Explore/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_speed_122008
More information about the Tutor
mailing list