python主动创建路径文件并创建日志log文件,可以显示时间信息(get_timestamp()),不需要可以去掉。
from datetime import datetime
def get_timestamp():
return datetime.now().strftime('%y%m%d-%H%M%S')
import logging
import os
def mkdir_and_rename(path):
if os.path.exists(path):
new_name = path + '_archived_' + get_timestamp()
print('Path already exists. Rename it to [{:s}]'.format(new_name))
logger = logging.getLogger('base')
logger.info('Path already exists. Rename it to [{:s}]'.format(new_name))
os.rename(path, new_name)
os.makedirs(path)