Specifying a Different Path for the Input Files
Hello,
when using the script on windows (I didn't try it on Linux) when specifying an input file which is not in the same directory as the script itself, the script complains about illegal characters such as the directory delimiters \ and /.
Is there any possibility to specify an input file, which is stored in another directory? Thanks.
Hi @r0bc94 ,
I didn't write this script with supporting Windows in mind at all but it's nice to hear that it also works in Windows as long as the script and target file are in the same directory. This means making this cross-platform is only a matter of handling Windows paths. That's probably why you are running into this issue because Windows paths are separated by \ . I am not sure if I can justify my time right now to work on this as things are a bit busy at work lately but I will leave the issue open and see if anyone is willing to contribute and submit a PR that will support both *nix and Windows at the same time. Or.... given time, I will slide this in next time I can find some free time post work hiatus.
Thanks
Btw, I just took a quick look at the code since it's been a while and it looks like it might be a much simpler problem than I thought.
Try removing illegal characters checking from the script. This is line 58 - 66. After that, it should stop complaining about illegal characters but of course it also won't check for all the other illegal characters either.
Again, once I find some free time, I will try to do a more official/cleaner update to see if we can fix that problem.
Thanks for your response. I didn't looked at the code yet, but I also was a bit confused about the error message:
←[91mERROR:←[0m Output file contains invalid characters such as / \ : ; \`.... Exiting...
since it actually also lists the *nix directory delimiter / as an invalid character (even if the check does not so).
Try removing illegal characters checking from the script. This is line 58 - 66. After that, it should stop complaining about illegal characters but of course it also won't check for all the other illegal characters either.
I will try this and see, if this works. Currently on windows when specifying the input and output files without a backslash inside the source and destination filenames, the output looks like so:
PS E:\Robin\Dokumente> python .\cpdf.py screen bla.pdf test.pdf
Compressing...
0% [##############################] 100% | ETA: 00:00:00
Total time elapsed: 00:00:00
1
Title: Compressing...
Started: 01/17/2021 16:14:25
Finished: 01/17/2021 16:14:25
Total time elapsed: 00:00:00
Compressed!
Traceback (most recent call last):
File ".\cpdf.py", line 136, in <module>
final_size = os.path.getsize(outFile)
File "C:\Users\Robin\AppData\Local\Programs\Python\Python38-32\lib\genericpath.py", line 50, in getsize
return os.stat(filename).st_size
FileNotFoundError: [WinError 2] Das System kann die angegebene Datei nicht finden: 'test.pdf'
PS E:\Robin\Dokumente\bewerbung\wohnung\anlagen>
It basically complains, that the output path of the file test.pdf could not be found. This is probably an issue about the provided path to the write() (or whatever function is used to write the output buffer).
Edit: I glaced at the source code and was wondering, why you are not using the pathlib module to handle the filepaths. Normally, this module provides a transparent way to handle either windows or unix paths (you don't need to worry about them). Is there a reason why this module isn't used?
Thanks for your PR but I am wondering if there's an even simpler fix for it. Can you check if the latest release (v1.3) works for Windows?
Thanks!
Closing due to lack of followup