cd 到用户定义的路径

发布于 2024-11-13 09:01:18 字数 910 浏览 1 评论 0原文

我想知道你是否可以帮助我完成我的新 python 程序。我最近在 GUI 中添加了一个浏览按钮,使事情变得更加“用户友好”。我告诉 python 仅在要求用户浏览文件时接受 *.pvt 文件...现在,我想知道如何告诉 python 采用用户浏览到的路径并打开 cmd 窗口[使用 subprocess. Popen("cmd.exe")] 并 cd 到该用户定义的路径..有什么想法吗???

这就是我到目前为止所拥有的...

 def OnAbout3(self, event):
           """
           Browse for file
           """
           wildcard = "Select File (*.pvt)|*.pvt"
           dialog = wx.FileDialog(None, "Choose a file",
                                  wildcard=wildcard,
                                  style=wx.OPEN)
           if dialog.ShowModal() == wx.ID_OK:
              path = dialog.GetPaths()
              #######this is where i wanted to do something like this:
              subprocess.Popen("cmd.exe")
              #I wished cmd could simply cd to the variable, path
              os.system('cd path')
              dialog.Destroy()

所以,显然,这不会 cd 到路径。我该怎么做?

I was wondering if you could help me with my new python program. I recently added a browse button to the GUI to make things more "user-friendly." I told python to only accept *.pvt files when the user is asked to browse for a file... Now, I am left wondering how to tell python to take the path the user browsed to and open a cmd window[using subprocess.Popen("cmd.exe")] and cd to that user defined path.. any ideas???

here's what i have so far...

 def OnAbout3(self, event):
           """
           Browse for file
           """
           wildcard = "Select File (*.pvt)|*.pvt"
           dialog = wx.FileDialog(None, "Choose a file",
                                  wildcard=wildcard,
                                  style=wx.OPEN)
           if dialog.ShowModal() == wx.ID_OK:
              path = dialog.GetPaths()
              #######this is where i wanted to do something like this:
              subprocess.Popen("cmd.exe")
              #I wished cmd could simply cd to the variable, path
              os.system('cd path')
              dialog.Destroy()

so, obviously, this doesn't cd to path. how can i do this??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜妞爱困 2024-11-20 09:01:18

您是否尝试过此操作:

subprocess.Popen('cmd.exe', cwd=path)

这是基于这样的假设:您实际上并不想要 cd,而是希望设置当前工作目录 - 这是 cd 的后置条件...

检查subprocess 模块更多精彩参数和示例!

Did you try this:

subprocess.Popen('cmd.exe', cwd=path)

This is based on the assumption, that you don't really want to cd, but instead want the current working directory to be set - which is the post condition of cd...

Check the subprocess module for more awesome parameters and examples!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文