![](/img/trans.png)
[英]Winforms (with Python): Drag file object to Windows Explorer
[英]Python file explorer in windows 7
我只想找到一種在Windows 7及更高版本中通過python代碼打開和關閉任何特定文件夾的方法,任何建議都會有很大幫助。 謝謝。
這是打開目錄
task = subprocess.Popen('explorer "C:\\', shell=True)
p = task.pid
這是通過PID關閉
os.popen('TASKKILL /PID ' + str(p) + ' /F')
問題在於它給我的結束代碼和錯誤:
ERROR:The proces "i.e 12086" not found.
我訪問文件的模式如下:
with open("file.txt", "r") as file:
# do stuff with file
這使用python
上下文管理自動關閉文件。
從這里查看如何從Windows命令行打開文件資源管理器:
import subprocess
subprocess.Popen(r'explorer /select,"C:\path\of\folder\file"')
http://www.geoffchappell.com/studies/windows/shell/explorer/cmdline.htm
要終止該過程,請執行以下操作:
import os
os.system("taskkill /pid <ProcessID>")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.