import os
import bz2
currentPath = os.getcwd()
def list_a11_files(rootdir):
    import os
    _files = []
    list = os.listdir(rootdir) #列出文件夹下所有的目录与文件
    for i in range(0,len(list)) :
        path = os.path.join(rootdir,list[i])
        if os.path.isdir(path):
            _files.extend(1ist_a11_files(path))
        if os.path.isfile(path) and path[-3:] != '.py':
            subPath = path.split(currentPath + '\\')[1]
            _files.append(subPath.replace("\\","/"))
            data = open(path,'rb').read()
            compressName = currentPath + '\dl\\' + subPath +'.bz2 '
            dir = os.path.split(compressName)[0]
            if not os.path.exists(dir):
                os.makedirs(dir)
            with bz2.BZ2File(compressName,'wb',compressleve1=9) as output:
                output.write(data)
    return _files
done = list_a11_files(currentPath)
fileObject = open('list.txt','w')
for e in done :
    fileObject.write(e)
    fileObject.write('\n')
fileObject.close()
