黑松山资源网 Design By www.paidiu.com
使用python脚本按照年月日生成多级目录,创建的目录可以将系统生成的日志文件放入其中,方便查阅,代码如下:
#!/usr/bin/env python #coding=utf-8 import time import os.path #获得当前系统时间的字符串 localtime=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) print('localtime='+localtime) #系统当前时间年份 year=time.strftime('%Y',time.localtime(time.time())) #月份 month=time.strftime('%m',time.localtime(time.time())) #日期 day=time.strftime('%d',time.localtime(time.time())) #具体时间 小时分钟毫秒 mdhms=time.strftime('%m%d%H%M%S',time.localtime(time.time())) fileYear='/data/python-scripts/inspector/AccountInspector/badJsidAccountLogs/'+year fileMonth=fileYear+'/'+month fileDay=fileMonth+'/'+day if not os.path.exists(fileYear): os.mkdir(fileYear) os.mkdir(fileMonth) os.mkdir(fileDay) else: if not os.path.exists(fileMonth): os.mkdir(fileMonth) os.mkdir(fileDay) else: if not os.path.exists(fileDay): os.mkdir(fileDay) #创建一个文件,以‘timeFile_'+具体时间为文件名称 fileDir=fileDay+'/timeFile_'+mdhms+'.txt' out=open(fileDir,'w') #在该文件中写入当前系统时间字符串 out.write('localtime='+localtime) out.close()
执行
[root@localhost AccountInspector]# python timeFile.py localtime=2017-01-22 10:20:52
进入文件夹下,可以看到文件目录已经存在了
[root@localhost 22]# pwd /data/python-scripts/inspector/AccountInspector/badJsidAccountLogs/2017/01/22
文件也已经生成
[root@localhost 22]# ll total 4 -rw-r--r--. 1 root root 29 Jan 22 10:20 timeFile_0122102052.txt
文件内容
localtime=2017-01-22 10:20:52
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对的支持。如果你想了解更多相关内容请查看下面相关链接
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年10月07日
2024年10月07日
- 班得瑞原装进口《第五张新世纪专辑:迷雾森林+EP》1CD[APE/CUE分轨][334.2MB]
- 田震.1997-顺其自然(日版)【红星生产社】【WAV+CUE】
- 小虫.1996-想得太美【滚石】【WAV+CUE】
- 谢采妘.2016-邓丽君名曲专辑【丰荣】【WAV+CUE】
- 张含韵.2007-一人一梦【天中文化】【WAV+CUE】
- 蟑螂乐队.1999-帮个忙【福茂】【WAV+CUE】
- 张宇.2001-替身【EMI百代】【WAV+CUE】
- 班得瑞原装进口《第六张新世纪专辑:日光海岸》1CD[APE/CUE分轨][339.5MB]
- 班得瑞原装进口《第七张新世纪专辑:梦花园》1CD[APE/CUE分轨][331.4MB]
- 班得瑞原装进口《第八张新世纪专辑:琉璃湖畔》1CD[APE/CUE分轨][286.4MB]
- 魏如萱.2011-在哪里(EP)【添翼创越】【WAV+CUE】
- 群星.1981-新金曲奖·青年创作园地12合辑(喜玛拉雅复刻版)【歌林】【WAV+CUE】
- 麦洁文.1989-新曲与精丫新艺宝】【WAV+CUE】
- SNH48《薄荷糖 (Mint Candy)》[320K/MP3][33.72MB]
- SNH48《薄荷糖 (Mint Candy)》[FLAC/分轨][78.59MB]