OS自动创建和系统时间名字一样的文件夹

利用OS自动创建和系统时间名字一样的文件夹

例子:

结果:创建一个文件夹2018_04_16_19_39_50,里边有三个文件夹FP/FN/TP

#!/usr/bin/python
# coding:utf-8

'''
# creat Folder same as system time
# Copyright 2018.4.16 Pulse Analyze Project
#   Author: super
#   All Rights Reserved.
'''

import os
import time
import datetime
import dateutil.tz

now = datetime.datetime.now(dateutil.tz.tzlocal())
timestampfp = now.strftime('%Y_%m_%d_%H_%M_%S')
dir_FP = '../plot/%s/FP' % \
             ( timestampfp)
if not os.path.exists(dir_FP):
    os.makedirs(dir_FP)

now = datetime.datetime.now(dateutil.tz.tzlocal())
timestampfn = now.strftime('%Y_%m_%d_%H_%M_%S')
dir_FN = '../plot/%s/FN' % \
         (timestampfn)
if not os.path.exists(dir_FN):
    os.makedirs(dir_FN)

now = datetime.datetime.now(dateutil.tz.tzlocal())
timestamptp = now.strftime('%Y_%m_%d_%H_%M_%S')
dir_TP = '../plot/%s/TP' % \
         (timestamptp)
if not os.path.exists(dir_TP):
    os.makedirs(dir_TP)
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页