资源简介

Python快速上手经典教程

资源截图

代码片段和文件信息

import os
import time

# 1. The files and directories to be backed up are
# specified in a list.
# Example on Windows:
# source = [‘“C:\\My Documents“‘]
# Example on Mac OS X and Linux:
source = [‘/Users/swa/notes‘]
# Notice we have to use double quotes inside a string
# for names with spaces in it.  We could have also used
# a raw string by writing [r‘C:\My Documents‘].

# 2. The backup must be stored in a
# main backup directory
# Example on Windows:
# target_dir = ‘E:\\Backup‘
# Example on Mac OS X and Linux:
target_dir = ‘/Users/swa/backup‘
# Remember to change this to which folder you will be using

# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target = target_dir + os.sep + \
         time.strftime(‘%Y%m%d%H%M%S‘) + ‘.zip‘

# Create target directory if it is not present
if not os.path.exists(target_dir):
    os.mkdir(target_dir)  # make directory

# 5. We use the zip command to put the files in a zip archive
zip_command = ‘zip -r {0} {1}‘.format(target
                                      ‘ ‘.join(source))

# Run the backup
print(‘Zip command is:‘)
print(zip_command)
print(‘Running:‘)
if os.system(zip_command) == 0:
    print(‘Successful backup to‘ target)
else:
    print(‘Backup FAILED‘)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件           0  2021-01-21 06:14  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?
     文件         312  2021-01-21 06:14  __MACOSX\._A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?
     文件        6148  2021-01-28 02:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?.DS_Store
     文件         120  2021-01-28 02:10  __MACOSX\A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?._.DS_Store
     目录           0  2021-01-21 06:14  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\
     文件         220  2021-01-21 06:14  __MACOSX\A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?._byte-of-python-master
     文件     2246672  2018-02-24 20:50  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-chinese-edition.pdf
     文件         276  2018-02-24 20:50  __MACOSX\A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?._byte-of-python-chinese-edition.pdf
     文件     2573227  2018-02-24 20:56  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master.zip
     文件         276  2018-02-24 20:56  __MACOSX\A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?._byte-of-python-master.zip
     文件       15919  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\oop.md
     文件        7050  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\exceptions.md
     文件       16893  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\data_structures.md
     文件       16553  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\basics.md
     文件        8048  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\more.md
     文件        6148  2021-01-28 02:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\.DS_Store
     文件         120  2021-01-28 02:10  __MACOSX\A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\._.DS_Store
     文件        3760  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\floss.md
     文件         559  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\dedication.md
     文件         807  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\SUMMARY.md
     文件         101  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\Makefile
     文件         503  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\book.json
     文件        4800  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\stdlib.md
     文件          95  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\poem.txt
     文件         675  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\translation_howto.md
     文件       12199  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\modules.md
     文件          94  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\INSTALL.md
     文件       20447  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\README.md
     目录           0  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\img\
     目录           0  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\programs\
     文件       12579  2018-01-28 05:10  A Byte of Python(绠€鏄嶱ython鏁欑▼)(绗?鐗?涓枃鐗?byte-of-python-master\problem_solving.md
............此处省略115个文件信息

评论

共有 条评论