Skip to content

Commit eb6671b

Browse files
committed
Add glob pattern expansion to pdfcompress.py for Windows compatibility
- Import `glob` and expand wildcard arguments (e.g., *.pdf) before processing. - Handles cases where the Windows shell does not auto‑expand globs, ensuring all matching PDFs are compressed.
1 parent 4f5fce5 commit eb6671b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

Programming/pdfcompress.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import platform
66
import argparse
7+
import glob
78

89
def get_gs_executable(custom_gs=None):
910
"""
@@ -101,7 +102,17 @@ def main():
101102

102103
gs_executable = get_gs_executable(args.gs)
103104

104-
for input_pdf in args.pdf_files:
105+
# Expand glob patterns (e.g., *.pdf) into actual file names
106+
expanded_files = []
107+
for pattern in args.pdf_files:
108+
matches = glob.glob(pattern)
109+
if matches:
110+
expanded_files.extend(matches)
111+
else:
112+
# If no matches, keep the original (might be a literal filename)
113+
expanded_files.append(pattern)
114+
115+
for input_pdf in expanded_files:
105116
if not os.path.isfile(input_pdf):
106117
print(f"File not found: {input_pdf}")
107118
continue

0 commit comments

Comments
 (0)