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
人气:417 ℃ 时间:2020-03-30 00:19:38
解答
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()
推荐
- Could you please tell me ____?A.how I can solve the problem B.how I could solve the problem
- Can you tell me how I can solve the problem quickly(改为同义句)
- 英语翻译
- I don't know how to solve the problem.的同义句
- Can you tell me how to get ( )the park?Sorry,I don't know the way ( )there.为什么选A?
- 帮我找一句句子,还要它的意思和赏析
- 已知A=2x+4y—2,B=-2x+y+3,则3A—4B=?
- 沪宁高速公路约长270千米,一辆客车和一辆轿车先后从上海出发去南京,客车先行50千米后,轿车再出发,客车平均每小时行80千米,轿车平均每小时行100千米,轿车几小时后追上客车?
猜你喜欢
- 问角平分线的定义在使用中,可以写作一个角是另一个角的形式,还,可以写作一个角是另一个角一半的形式,
- 那一次我懂得了——作文
- 求函数y=log1/2[cos(x/3+π/4)]的单调递增区间.【1/2为底数】
- 集合A={(x,y)/y=3x-2},B={(x,y)/y=x方}则A交B=?
- I won't have a whisky,thank you.It's not that I don't drink,_____that I don't drink and drive.
- 比较大小1/25( ) 0.05;1又7/8( )1.8
- 已知cosα2-sinα2=1−sinα,且α是第二象限角,则α2是第_象限角.
- 要搬10张桌子,老师搬一张,两个同学抬一张,有3个老师,还要几个同学一次搬完