database_tools中新增跨平台打开文件或文件夹的功能
This commit is contained in:
parent
8198c01dd6
commit
f23b4183d9
|
|
@ -1,4 +1,4 @@
|
|||
import json,re,os,Levenshtein,fitz,time,sys
|
||||
import json,re,os,Levenshtein,fitz,time,sys,subprocess
|
||||
import pandas as pd
|
||||
import pyperclip
|
||||
|
||||
|
|
@ -2122,5 +2122,23 @@ def TitleIDTupleListtoString(correspoinding_list): #将(标题,题号字符串)
|
|||
output_string += f"{count}. {corresp[0]}: {corresp[1]}\n"
|
||||
return output_string
|
||||
|
||||
def startfile(filepath): #跨平台打开文件或文件夹
|
||||
isfile = os.path.isfile(filepath)
|
||||
osname = sys.platform
|
||||
if osname == "win32":
|
||||
if not isfile:
|
||||
ret = subprocess.Popen(["explorer",filepath])
|
||||
if isfile:
|
||||
ret = subprocess.Popen(["start",filepath], shell=True)
|
||||
elif osname == "darwin":
|
||||
ret = subprocess.Popen(["open",filepath])
|
||||
elif osname == "linux":
|
||||
ret = subprocess.Popen(["xdg-open",filepath])
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("数据库工具, import用.")
|
||||
Reference in New Issue