I don't know how to use baiduhi.Can you tell me how to solve the following problem?假设有个目录下有很多个文件夹,分为两类 A和B,A里面都是.txt文档,B里面又有文件夹,二文件夹 下才是.txt 怎样把A中.txt单独压缩
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/29 01:14:24
![I don't know how to use baiduhi.Can you tell me how to solve the following problem?假设有个目录下有很多个文件夹,分为两类 A和B,A里面都是.txt文档,B里面又有文件夹,二文件夹 下才是.txt 怎样把A中.txt单独压缩](/uploads/image/z/9164757-21-7.jpg?t=I+don%27t+know+how+to+use+baiduhi.Can+you+tell+me+how+to+solve+the+following+problem%3F%E5%81%87%E8%AE%BE%E6%9C%89%E4%B8%AA%E7%9B%AE%E5%BD%95%E4%B8%8B%E6%9C%89%E5%BE%88%E5%A4%9A%E4%B8%AA%E6%96%87%E4%BB%B6%E5%A4%B9%2C%E5%88%86%E4%B8%BA%E4%B8%A4%E7%B1%BB+A%E5%92%8CB%2CA%E9%87%8C%E9%9D%A2%E9%83%BD%E6%98%AF.txt%E6%96%87%E6%A1%A3%2CB%E9%87%8C%E9%9D%A2%E5%8F%88%E6%9C%89%E6%96%87%E4%BB%B6%E5%A4%B9%2C%E4%BA%8C%E6%96%87%E4%BB%B6%E5%A4%B9+%E4%B8%8B%E6%89%8D%E6%98%AF.txt+%E6%80%8E%E6%A0%B7%E6%8A%8AA%E4%B8%AD.txt%E5%8D%95%E7%8B%AC%E5%8E%8B%E7%BC%A9)
I don't know how to use baiduhi.Can you tell me how to solve the following problem?假设有个目录下有很多个文件夹,分为两类 A和B,A里面都是.txt文档,B里面又有文件夹,二文件夹 下才是.txt 怎样把A中.txt单独压缩
I don't know how to use baiduhi.Can you tell me how to solve the following problem?
假设有个目录下有很多个文件夹,分为两类 A和B,A里面都是.txt文档,B里面又有文件夹,二文件夹 下才是.txt 怎样把A中.txt单独压缩在A文件夹里,B中以则子文件夹为单位压缩在B中
Assuming that a directory has many folders.There are two types of these folders,A and B.
In the A ,all the documents are .txt documents.But B has lots of folders like A.
How to put .TXT compression alone in A
and put subfolders compression in the B
I don't know how to use baiduhi.Can you tell me how to solve the following problem?假设有个目录下有很多个文件夹,分为两类 A和B,A里面都是.txt文档,B里面又有文件夹,二文件夹 下才是.txt 怎样把A中.txt单独压缩
Gotha,wait a moment,I'm writing it.
This code is written according to the cases you just described
the APath and BPath should be the path of A and B folder.
#
import tarfile
import os
APath = 'A'
dirA = os.walk(APath).next()[2]
tarA = tarfile.open('A/txt.tar.bz','w:bz2')
for file in dirA:
tarA.add(os.path.join(APath,file))
tarA.close()
BPath = 'B'
dirB = os.walk(BPath).next()[1]
os.chdir('B')
for directory in dirB:
tar = tarfile.open(directory+'tar.bz','w:bz2')
tar.add(directory)
tar.close()