Any Python code for CD-R writing on a Windows box?
John Hunter
jdhunter at ace.bsd.uchicago.edu
Sun Dec 1 10:03:06 EST 2002
>>>>> "David" == David Lees <abcdebl2nospammyyy at bellatlantic.net> writes:
David> It would be neat to write short python programs for
David> selectively writing files onto my CD-RW drive for backups
David> on my Win98 box. Is there any Python code for writing a
David> file or directory onto a CD-R disc?
If you have a command line program that can do it, you can call the
program from python with, eg, os.system or os.popen
cdrecord and mkisofs are 2 excellent tools from the UNIX world that
you can use to do this. I haven't used them under windows, but they
do run on windows (it may require cygwin, I'm not sure)
Here is an example script. You may have to change the code a bit to
meet the particulars of your system, but it will give you the idea
import os, sys
tmpfile = 'temp.iso' # could also use python's tempfile module
command = 'mkisofs -r -o %s %s ' % (tmpfile, ' '.join(sys.argv[1:]))
print 'Executing %s' % command
c1 = os.popen(command)
c1.close()
# remove dummy and update device number when all is well
command = 'cdrecord dev=1,0,0 -dummy %s' % tmpfile
print 'Executing %s' % command
c2 = os.popen(command)
c2.close()
os.remove(tmpfile)
You can do this without intervening tmp files on systems with piped
using stdin and stdout, to burn the file directly to the burner. I
don't know if this will work under windows or not.
Good luck,
John Hunter
More information about the Python-list
mailing list