1
내 디렉토리에 압축 파일이 많이 있습니다. 각 zip 파일의 파일 수를 얻고 싶습니다.Python을 사용하여 zip 파일 형식이 다른 파일 수를 계산합니다.
file_name file_format
nature jpg 2, png 1
지금까지 내가 내용을 인쇄하는 데 성공하지만
앞으로 나아갈 수있는 방법을 모른다 : 예를 들어, 내가 출력 다음 싶어의 zip 파일 "nature.zip"를 가정 해 봅시다from zipfile import ZipFile
import os
directory = r"C:\Users\Lenovo\data_2"
for folder, subfolders, files in os.walk(directory):
for file in files:
if file.endswith(".zip"):
# opening the zip file in READ mode
with ZipFile(directory+ '/'+ file, 'r') as zip:
# printing all the contents of the zip file
zip.printdir()
고맙습니다.
당신이 zip 파일의 하위 폴더를 통해 재귀해야합니까? – MustacheMoses