我正在尝试使用该zipfile库在Django中解压缩zip文件.
这是我的代码:
if formtoaddmodel.is_valid():
content = request.FILES['content']
unzipped = zipfile.ZipFile(content)
print unzipped.namelist()
for libitem in unzipped.namelist():
filecontent = file(libitem,'wb').write(unzipped.read(libitem))
Run Code Online (Sandbox Code Playgroud)
这是输出 print unzipped.namelist()
['FileName1.jpg', 'FileName2.png', '__MACOSX/', '__MACOSX/._FileName2.png']
Run Code Online (Sandbox Code Playgroud)
我想知道最后两个项目是什么 - 它看起来像路径.我不关心那里 - 那怎么有办法过滤掉它们?
https://superuser.com/questions/104500/what-is-macosx-folder
if libitem.startswith('__MACOSX/'):
continue
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2577 次 |
| 最近记录: |