Python中使用子进程的脚本不起作用

问题描述 投票:0回答:1

我正在使用一个脚本,在该脚本中输入数字,该脚本会为您创建一个文件夹并在该文件夹中打开文件资源管理器。但我对此有疑问。

import subprocess
import os


##saisie du numero de dossier
compostage = str(input('Numero : '))
volume = ('C:')
dossierPrincipal = ('''\\test\\''')
slash = '\\'

##
# Directory 
directory = compostage

# Parent Directory path 
parent_dir = "C:/test/"

#We make only one var for the func
myPath = parent_dir + directory

# Path 
path = os.path.join(myPath) 
##We create a condition to be sure te folder is created
if not os.path.exists(path):
    os.makedirs(path)
    ##We inform the user of the creation of the folder
    print("Directory '% s' well created" % path) 
elif os.path.exists(path):
    ##We inform the user that the folder in question already exists
    print("Directory '% s' already exists" % path) 

##We build the entire path
pathComplet = str(volume+dossierPrincipal+compostage)

##Path verification
print(pathComplet)

##Variable Construction
commandeOuverture = str('('+("""r'explorer """)+'"'+myPath+'"'')')

##Directory verification
print ('La commande est : ', commandeOuverture)

##We open the folder using Popen
subprocess.Popen([commandeOuverture], shell=True)

##We open the folder using Popen if the command above doesn't work
#subprocess.Popen(r'explorer "C:\test\"')

输出为:The specified path was not found.我不知道该怎么办,这就是为什么我在这个论坛上写这句话的原因

python subprocess
1个回答
0
投票

尝试使用命令os.makedirs(“您想要的路径”)来测试您想要创建的目录是否可行。通常,如果使用公司笔记本电脑,则限制在C:目录中创建新文件夹。您可以尝试在其他驱动器或桌面上创建文件夹。希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.