[英]Unzipping all .bz2 files in each folder and subfolder in python
I have the code below which starts at a directory and is suppose to go into each folder, open cmd and exec the statement below. 我有下面的代码,该代码从目录开始,并假设进入每个文件夹,打开cmd并执行下面的语句。
I can see it going into each directory but the cmd screen flashes but nothing is extracted. 我可以看到它进入每个目录,但cmd屏幕闪烁,但未提取任何内容。 Am I doing something wrong?
难道我做错了什么?
import os
for dirpath, dirnames, filenames in os.walk('.', topdown = True):
os.system('7z e *.bz2')
print(dirpath)
Thank you very much! 非常感谢你!
You should make use of the dirpath
and filenames
variables while iterating through the os.walk
generator: 在遍历
os.walk
生成器时,应使用dirpath
和filenames
变量:
import os
for dirpath, _, filenames in os.walk('.', topdown = True):
for filename in filenames:
if filename.endswith('.bz2'):
os.chdir(dirpath)
os.system('7z e ' + os.path.join(dirpath, filename))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.