首页 > 编程知识 正文

python解析json文件,python 解压文件

时间:2023-05-06 15:09:31 阅读:110290 作者:968

I ' mtryingtoextractzippedfolderusingcodefoundhere。

efunzip(source_filename,dest_dir ) :

with zipfile.zipfile (source _ filename ) as zf:

for member in zf.infolist () :

Words=member.filename.split('/' ) )。

for word in words[:-1]:

drive,word=OS.path.splitdrive,word

head,word=OS.path.split(word ) )。

ifwordin(OS.curdir,os.pardir,'') : continue

ZF.extract(member,path ) ) )。

But when trying to extract,for example,WordPress.zipwithdirectorystructure

wordpress/

-wp-content/

---somefile.php

-wp-config.php

-index.php

ionlygetthefilesinfolderbelowrootfolderorwordpress/in this case.soigetwordpress/WP-content/some file.phpbutnottthefiles

解决方案

thefirstplacetolookisthedocumentation :

zipfile.extractall([path[,members[,pwd]]] )

Applying that to your situation,I'd try:

efunzip(source_filename,dest_dir ) :

with zipfile.zipfile (source _ filename ) as zf:

ZF.extractall(dest_dir ) )。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。