显示zip里面的文件列表,显示zip文件列表,[Python]代码de


[Python]代码

def zf(filename):    """List all files in the zipfile"""    import zipfile    if zipfile.is_zipfile(filename):        zf=zipfile.ZipFile(filename)        llen=len(zf.namelist())        print("{0:<10}{1:<20}{2:<10}{3:<10}".format("FileName","Datetime","Size","CompressSize"))        for zff in zip(range(llen),zf.infolist()):            nm=zff[1].filename            sz=zff[1].file_size            csz=zff[1].compress_size            dt=" ".join(["/".join([str(i) for i in zff[1].date_time[0:3]]),":".join([str(i) for i in zff[1].date_time[3:6]])])        print("{0:<10}{1:<20}{2:<10}{3:<10}".format(short(nm),dt,str(sz)+"Byte",str(csz)+"Byte"))    else:        print("Not a zipFile!")def short(sstr,emit="...",size=10):        """           缩短文件名或字符串输出        """    reallen=len(sstr)    if reallen>size+len(emit):        sstr=sstr[:size/2-len(emit)/2]+emit+sstr[-1:0-size/2+len(emit)/2]    return sst

评论关闭