Last active
November 20, 2024 20:46
-
-
Save tijme/35da600ffb5830b817d81635c46bfce0 to your computer and use it in GitHub Desktop.
Generate an ISO image/file using Python on Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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