一、实现创建文件夹和日志
#!/usr/bin/env python # -*- coding:utf-8 -*- # Author: nulige import os import datetime #获取系统时间 log_path_suffix = datetime.datetime.now().strftime('%Y-%m-%d ') #创建文件夹 folder_name = 'log' root_directory = 'D:pythondisk_monitor' try: os.mkdir(root_directory + folder_name) except OSError: pass #创建文件 file_path = r'D:pythondisk_monitorlogevent-ext-'+log_path_suffix+'.log' f = open(file_path, 'a')