Skip to content

Instantly share code, notes, and snippets.

@tijme
Last active September 18, 2023 20:07
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tijme/35da600ffb5830b817d81635c46bfce0 to your computer and use it in GitHub Desktop.
Save tijme/35da600ffb5830b817d81635c46bfce0 to your computer and use it in GitHub Desktop.
Generate an ISO image/file using Python on Windows
# pip install pycdlib
try:
from cStringIO import StringIO as BytesIO
except ImportError:
from io import BytesIO
import pycdlib
iso = pycdlib.PyCdlib()
iso.new(interchange_level=4)
targetfilenameFirst = 'YourFile'
targetFilenameExt = 'exe'
targetfilename = '{}.{}'.format(targetfilenameFirst, targetFilenameExt)
targetfilehandle = open(targetfilename, 'rb')
targetfilebody = targetfilehandle.read()
iso.add_fp(BytesIO(targetfilebody), len(targetfilebody), '/' + targetfilename + ';1')
iso.write('{}.iso'.format(targetfilenameFirst))
iso.close()
targetfilehandle.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment