--only option to extract files by extension

This commit is contained in:
Preciado12Caesar 2025-07-11 23:43:23 -05:00
parent 74f26d5dfd
commit 7bef1693e5

View file

@ -323,6 +323,7 @@ if __name__ == "__main__":
parser.add_argument('-l', '--list', action='store_true', help='List files in archive ARCHIVE.') parser.add_argument('-l', '--list', action='store_true', help='List files in archive ARCHIVE.')
parser.add_argument('-x', '--extract', action='store_true', help='Extract FILEs from ARCHIVE.') parser.add_argument('-x', '--extract', action='store_true', help='Extract FILEs from ARCHIVE.')
parser.add_argument('--only', metavar='EXT', help='Optional: extract only files with this extension (e.g., .png)')
parser.add_argument('-c', '--create', action='store_true', help='Creative ARCHIVE from FILEs.') parser.add_argument('-c', '--create', action='store_true', help='Creative ARCHIVE from FILEs.')
parser.add_argument('-d', '--delete', action='store_true', help='Delete FILEs from ARCHIVE.') parser.add_argument('-d', '--delete', action='store_true', help='Delete FILEs from ARCHIVE.')
parser.add_argument('-a', '--append', action='store_true', help='Append FILEs to ARCHIVE.') parser.add_argument('-a', '--append', action='store_true', help='Append FILEs to ARCHIVE.')
@ -434,6 +435,11 @@ if __name__ == "__main__":
else: else:
files = archive.list() files = archive.list()
# optional filter --only
if arguments.only:
files = [f for f in files if f.lower().endswith(arguments.only.lower())]
# Create output directory if not present. # Create output directory if not present.
if not os.path.exists(output): if not os.path.exists(output):
os.makedirs(output) os.makedirs(output)