#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) # 把文件复制到刚刚生成的文件夹中(文件,文件,文件)