简体   繁体   English

无法在资源管理器中打开文件

[英]Can't Open file in explorer

i have checked here , and tried the code independently and it worked...but inserting the code in my QTreeView app...it opens up the explorer user libraries with 'My Documents' in focus 我在这里检查 ,并独立尝试了代码,它确实起作用了...但是将代码插入到我的QTreeView应用程序中...它打开了以“我的文档”为焦点的资源管理器用户库

i use subprocess.Popen(r'explorer /select,"file_path"') 我使用subprocess.Popen(r'explorer /select,"file_path"')

here is my code 这是我的代码

def on_clicked(self, index):
    # self.path = self.fileSystemModel.fileInfo(index).absoluteFilePath()
    self.path = self.fileSystemModel.filePath(index)
    print(self.path

def tabMenu(self, positon):
    self.tmenu = QMenu()

    self.open = self.tmenu.addAction('Open')
    self.open_file_location = self.tmenu.addAction('Open File Location')

    self.tmenu.addActions([self.open, self.open_file_location])
    action = self.tmenu.exec_(self.temp_treeView.viewport().mapToGlobal(position))

    if action == self.open:
        os.startfile(self.path, 'open')
    elif action == self.open_file_location:
        print(self.path)
        subprocess.Popen(r'explorer /select,' + self.path)

self.path = self.fileSystemModel.filePath(index)返回带有/文件路径, subprocess.Popopen(r'explorer /select,"path")无法访问该文件subprocess.Popopen(r'explorer /select,"path") ..您需要将/转换为\\以使其work ...通过subprocess.Popen(r'explorer /select,'+"{}".format(path).replace('/', '\\\\'))转换了字符串subprocess.Popen(r'explorer /select,'+"{}".format(path).replace('/', '\\\\'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM