Python入门(简明Python教程)——巳

一个压缩文件的副本

import os
import time

source=['C:\inher\GRE','C:\inher\hey']
target_dir='C:\inher\mew'
#print(os.sep)
target=target_dir+os.sep+time.strftime('%Y.%m.%d %H:%M.%S')+'.zip'

if not os.path.exists(target_dir):
    os.mkdir(target_dir)

zip_command='zip -r {0} {1}'.format(target,' '.join(source))
#print(os.system==zip_command)
print('Zip command is:')
print(zip_command)
print('Running')
if os.system(zip_command)==0:
    print('Successful backup to',target)
else:
    print('Failed')
os.system('pp.doc')

我并未成功运行上面这段代码(虽然我相信上面这段代码是正确的),因为我没有安装unix系统也没有安装gnu32。

注意“os.sep”即为各种操作系统上文件路径的分隔符。

猜你喜欢

转载自blog.csdn.net/qq_40703975/article/details/81254556