Я думаю, что Pathlib Path может сделать вашу жизнь действительно проще.
Из сообщения об ошибке, которое вы разместили, я понимаю, что вы пытаетесь пройти путь с обычной /
... ('La commande est : ', '(r\'explorer "C:/test/5")')
однако windows ОС работает с backsla sh в качестве разделителя пути. В приведенном ниже пути к коду вы сначала печатаете правильный путь windows в переменной pathComplet
, однако для своей команды вы используете myPath, который, по-видимому, не имеет правильного разделителя пути.
##Path verification
print(pathComplet)
##Variable Construction
commandeOuverture = str('('+("""r'explorer """)+'"'+myPath+'"'')')
Не могли бы вы попробовать
from pathlib import Path
myPath = Path(myPath)
PS: Извините, что испортил ссылку https://docs.python.org/3/library/pathlib.html
Редактировать:
Полный код, открывший правильный каталог в проводнике для меня:
# -*- coding: utf-8 -*-
import subprocess
from pathlib import Path
##saisie du numero de dossier
directory = str(input('Numero : '))h
parent_dir = Path("C:/test")
myPath = parent_dir / directory
##We create a condition to be sure te folder is created
if not myPath.exists():
myPath.mkdir()
##We inform the user of the creation of the folder
print("Directory '% s' well created" % myPath)
elif myPath.exists():
##We inform the user that the folder in question already exists
print("Directory '% s' already exists" % myPath)
##Variable Construction
commandeOuverture = "explorer " + str(myPath)
##We open the folder using Popen
subprocess.Popen(commandeOuverture, shell=True)