import os class FileDownload: def __init__(self): self.exclude = ['db.sqlite3', 'logs', 'media', 'Pipfile', 'Pipfile.lock', 'Readme.md'] # 不須要打包的文件 self.file_list = [] def get_file(self, path): if os.path.isfile(path): self.file_list.append(path) elif os.path.isdir(path): for file in os.listdir(path): if file not in self.exclude and not file.startswith('__') and not file.startswith('.'): new_dir = os.path.join(path, file) if not os.path.isdir(new_dir): self.file_list.append(new_dir) else: self.get_file(new_dir) if __name__ == '__main__': filepath = r'C:\Users\zhang\PycharmProjects\server' # 項目所在目錄 file_obj = FileDownload() file_obj.get_file(filepath) file_list = file_obj.file_list # 每個文件的絕對路徑 with open('code.txt', encoding='utf-8', mode='w+') as w: # 最終須要寫入的文件:code.txt for file in file_list: # 循環文件列表,對文件進行讀操做 with open(file, encoding='utf-8', mode='r') as f: for line in f.readlines(): w.write(line)
ip轉int與int轉ipsql