Python:实现文件归档
| [日期:2012-02-14] |
来源:Linux社区
作者:dyx1024 |
[字体:大 中 小]
|
初学 Python,整理了下书上的例程,做为学习的第一个实用程序。
-
-
-
-
- import os
- import time
-
-
- source = [r'E:\360Downloads']
-
-
- target_dir = 'E:\\backup\\'
-
-
- today = target_dir + time.strftime('%Y%m%d')
- now = time.strftime('%H%M%S')
-
-
- comment = input('Enter a comment:')
- if len(comment) == 0:
- target = today + os.sep + now + '.zip'
- else:
- target = today + os.sep + now + '_' + \
- comment.replace(' ', '_') + '.zip'
-
-
- if not os.path.exists(today):
- os.mkdir(today)
- print('Successfully created directory', today)
-
-
- zip_command = "winrar a %s %s" %(target, ' '.join(source))
-
-
- if os.system(zip_command) == 0:
- print('Successful backup to', target)
- else:
- print('Backup failed')

评论声明
- 尊重网上道德,遵守中华人民共和国的各项有关法律法规
- 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
- 本站管理人员有权保留或删除其管辖留言中的任意内容
- 本站有权在网站内转载或引用您的评论
- 参与本评论即表明您已经阅读并接受上述条款
|
|
第 1 楼 匿名 发表于 2013/7/13 19:31:22太感谢了
|
|