Added -d and -t switches for extract subcommand

This commit is contained in:
Rob McMullen 2021-10-09 11:24:12 -07:00
parent 414ed5f3e3
commit 5dde84c68e
1 changed files with 9 additions and 0 deletions

View File

@ -109,12 +109,19 @@ def extract_files(image, files):
output = dirent.filename
if options.lower:
output = output.lower()
if options.dir:
if not os.path.exists(options.dir):
os.makedirs(options.dir)
output = os.path.join(options.dir, output)
if not options.dry_run:
data = image.get_file(dirent)
if os.path.exists(output) and not options.force:
print("skipping %s, file exists. Use -f to overwrite" % output)
continue
print("extracting %s -> %s" % (name, output))
if options.text:
data = data.replace(b'\x7f', b'\t')
data = data.replace(b'\x9b', b'\n')
with open(output, "wb") as fh:
fh.write(data)
else:
@ -480,6 +487,8 @@ def run():
extract_parser.add_argument("-l", "--lower", action="store_true", default=False, help="convert extracted filenames to lower case")
#extract_parser.add_argument("-n", "--no-sys", action="store_true", default=False, help="only extract things that look like games (no DOS or .SYS files)")
extract_parser.add_argument("-e", "--ext", action="store", nargs=1, default=False, help="add the specified extension")
extract_parser.add_argument("-d", "--dir", action="store", default=False, help="extract to the specified directory")
extract_parser.add_argument("-t", "--text", action="store_true", default=False, help="convert text files to unix-style text files")
extract_parser.add_argument("-f", "--force", action="store_true", default=False, help="allow file overwrites on local filesystem")
extract_parser.add_argument("files", metavar="FILENAME", nargs="*", help="if not using the -a/--all option, a file (or list of files) to extract from the disk image.")