I'm trying do symbolic links in Python, and on my tests it works ok, until it receives a path with spaces in the name. I change .py extension to .command to run in MacOS. The functionality is simple:
- The program asks to drag or type the path that I wish a symbolic link.
Then asks the target path to create the link
So finally, the link is created (of course if without spaces).
It works when there are no spaces in the path, so can anyone help me?
#!/usr/bin/env python
# Importa biblioteca os
import os
# Recebe path de origem e destino
source = str(input("Digite ou arraste a path Job: "))
target = str(input("Path para criação do link simbólico: "))
# Armazena último diretório em uma váriavel
last_dir = source.rsplit("/", 1)[1]
# Criação do link simbólico
if os.path.exists(source.strip()):
try:
link = target.strip()+"/"+last_dir.strip()
print(link)
# link.replace(" ","")
os.symlink(source.strip(), link)
print("Link criado com sucesso")
except IOError as err:
print(err)
else:
print("Path inexistente")