import os
import tarfile
dst = '/destination/directory/path/'
src = '/source/directory/path/'
# list current date
heute = dt.date.today().strftime('%Y%m%d_')
# assuming only have directories in current directory
for d in os.listdir(src):
# define .tar destination filename
dst_fn = dst + heute + d + '.tar'
with tarfile.open(dst_fn, 'w') as fid:
fid.add(d)
使用
os.stat()
获取上次修改的时间,datetime
将其转换为所需的字符串时间戳。在好吧,您已经将Python和shell/sh标记为关键字,所以这里对这两个都进行了标记。在
Python
巴什
^{pr2}$这两种方法都应该为每个感兴趣的目录创建一个tar文件。我的建议是:创建一个虚拟目录,并在实际操作之前对每个目录进行测试,以确保。。。在
相关问题 更多 >
编程相关推荐