tkinter常用工具函数utils
from tkinter.filedialog import askopenfilename,askdirectory
import shutil
import os
def openfile():
file_path = askopenfilename(title='请选择文件')
return file_path
def opendir():
dir_path = askdirectory(title='请选择文件夹')
return dir_path
def write_file_rewrite(content,file_path):
with open(file_path,'w',encoding='utf-8') as file:
file.write(content)
def write_file_append(content,file_path):
with open(file_path, 'a', encoding='utf-8') as file:
file.write(content)
def read_file(file_path):
with open(file_path,'r') as file:
return file.readlines()
def get_alldirs_path(dir_path):
tuples = os.walk(dir_path)
dirs = []
for tuple in tuples:
dirs.append(tuple[0])
return dirs
def get_dirs_path(dir_path):
files_dirs_path = os.listdir(dir_path)
dirs_path = []
for i in files_dirs_path:
if(os.path.isdir(i)):
dir_p = os.path.join(dir_path,i)
dirs_path.append(dir_p)
return dirs_path
def get_files_path(dir_path):
files_dirs_path = os.listdir(dir_path)
files_path = []
for i in files_dirs_path:
if (os.path.isfile(i)):
filw_p = os.path.join(dir_path,i)
files_path.append(filw_p)
return files_path
def get_file_parent_dir(file_path):
pass
def get_dir_parent_dir(dir_path):
pass
def copyfile(src_path,dst_path):
pass
def movefile(src_path,dst_path):
pass
def renamefile(src_path,dst_path):
pass
def is_exist_file(file_path):
pass
def removefile():
pass
def getcwd():
pass
def makedir():
pass
def copydir():
pass
def movedir():
pass
def renamedir():
pass
def deletedir():
pass
if __name__ == '__main__':
print(get_files_path(r"D:\workplace\python\RealAug"))