Python small exercise-7 os.startfile() double-click to open the file

import os

#print(os.startfile(r'D:\项目'))
print(os.listdir(r'D:\项目'))

def open_files_in_dir(path):
	for file in os.listdir(path):
		filepath = os.path.join(path,file)
		if os.path.isdir(filepath):
			open_files_in_dir(filepath)
		else:
			os.startfile(filepath)
		
path = r'D:\项目'
open_files_in_dir(path)

Guess you like

Origin blog.csdn.net/KathyLJQ/article/details/107974212