Python Forum
OSX: copied path has escape character - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: OSX: copied path has escape character (/thread-8929.html)



OSX: copied path has escape character - ronjan - Mar-13-2018

On OSX, copied path has backslash character to escape spaces in directory name.

e.g. /Users/ronsair/Downloads/test\ -\ folder

os.path.exists(<path above>) returns false.

Do I need to remove escape character, or there is a more elegant way to do this?


RE: OSX: copied path has escape character - Larz60+ - Mar-13-2018

Is the actual path: /Users/ronsair/Downloads/test/folder?
or /Users/ronsair/Downloads/test-folder?
on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder


RE: OSX: copied path has escape character - ronjan - Mar-13-2018

I don't know if this is the best, considering cross-platform compatibility. But I'm going with this.
path = path.strip().replace('\\', '')



RE: OSX: copied path has escape character - ronjan - Mar-14-2018

(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
It's
test[space]-[space]folder

(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
(Mar-14-2018, 05:08 PM)ronjan Wrote:
(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
It's test[space]-[space]folder
(Mar-14-2018, 05:08 PM)ronjan Wrote:
(Mar-13-2018, 04:03 PM)Larz60+ Wrote: Is the actual path: /Users/ronsair/Downloads/test/folder? or /Users/ronsair/Downloads/test-folder? on other OS's the escape for backslash is another backslash e.g.: /Users/ronsair/Downloads/test\\folder
It's test[space]-[space]folder

Screenshots:
Directory:
https://drive.google.com/file/d/1nl735uzx3pHG9bmYm4eeM_CNn_BBZ375/view?usp=sharing
Issue:
https://drive.google.com/file/d/1IMZTXN78L_yEUYmGJC823oOooLjlih3T/view?usp=sharing


RE: OSX: copied path has escape character - ronjan - Mar-14-2018

I figured out that, the issue highlighted is related more to OS behaviour.

I had been using the advantage of OSX, that when you copy [Cmd + C] a file and directory and paste it in terminal, the result is the absolute path, but with escape sequence if required. May be this is not the best way if you really want to copy the path. To copy the path, in the context menu, press [option] to switch to 'Copy ... as Pathname'.