莫愁前路无知己,天下谁人不识君。。。。

python小编程-------每天生成一个文件夹

上一篇 / 下一篇  2017-12-01 10:53:08 / 个人分类:python 小编程

#coding:utf-8
import time, os
basePath = 'e:\\work\\'
thisYear = str(time.localtime()[0])
thisMonth = str(time.localtime()[1])
thisDay = time.strftime("%Y-%m-%d", time.localtime())
yearPath = basePath + thisYear
monthPath = basePath + thisYear + '\\' + thisMonth
dayPath = basePath + thisYear + '\\' + thisMonth + '\\' + thisDay
if not os.path.exists(yearPath):
    os.mkdir(yearPath)
if not os.path.exists(monthPath):
    os.mkdir(monthPath)
if not os.path.exists(dayPath):
    os.mkdir(dayPath)
os.popen("explorer.exe" + " " + dayPath)
os.popen("exit")
# 这个程序的功能非常的简单,就是每天在系统中新建一个文件夹。文件夹即当前的时间
#os.system("explorer.exe" + " " + dayPath)
#os.system("exit")    # 在外面调用会出现python弹窗

综合应用:
def create_dir():
    basePath = 'e:\\work\\'
    thisYear = str(time.localtime()[0])
    thisMonth = str(time.localtime()[1])
    thisDay = time.strftime("%Y-%m-%d", time.localtime())
    yearPath = basePath + thisYear
    monthPath = basePath + thisYear + '\\' + thisMonth
    dayPath = basePath + thisYear + '\\' + thisMonth + '\\' + thisDay
    if not os.path.exists(yearPath):
        os.mkdir(yearPath)
    if not os.path.exists(monthPath):
        os.mkdir(monthPath)
    if not os.path.exists(dayPath):
        os.mkdir(dayPath)
    os.popen("explorer.exe" + " " + dayPath)
    os.popen("exit")
    # os.system("explorer.exe" + " " + dayPath)
    # os.system("exit")    # 在外面调用会出现python弹窗
    return dayPath
def mycopy(srcpath,dstpath):
    if not os.path.exists(srcpath):
        print "srcpath not exist!"
    if not os.path.exists(dstpath):
        print "dstpath not exist!"
    for root, dirs, files in os.walk(srcpath, True):
        for eachfile in files:
            shutil.copy(os.path.join(root, eachfile), dstpath)
srcpath = 'e:\\testandtry\\images'
dstpath = create_dir()
mycopy(srcpath, dstpath)        # 把文件复制到刚刚生成的文件夹中(文件,文件,文件)

TAG: Python python 文件夹

 

评分:0

我来说两句

Open Toolbar