Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifying a Different Path for the Input Files #4

Open
r0bc94 opened this issue Jan 17, 2021 · 4 comments · May be fixed by #5
Open

Specifying a Different Path for the Input Files #4

r0bc94 opened this issue Jan 17, 2021 · 4 comments · May be fixed by #5

Comments

@r0bc94
Copy link

r0bc94 commented Jan 17, 2021

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.

@hkdb
Copy link
Owner

hkdb commented Jan 17, 2021

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

@hkdb
Copy link
Owner

hkdb commented Jan 17, 2021

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.

@r0bc94
Copy link
Author

r0bc94 commented Jan 17, 2021

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?

@r0bc94 r0bc94 linked a pull request Jan 17, 2021 that will close this issue
@hkdb
Copy link
Owner

hkdb commented Jun 24, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants