I have a problem with my zip file program where if I create a zip file, and it puts itself in the map of the files I want to zip, the program goes in a loop where the zip file keeps putting itself in it and the size of the file keeps growing until your computer starts to crash.
I have been looking for a while now but can't find a solution.
The real issue is that sometimes it does it and when I test it another time, it doesn't do it.
(Also in the def walk line it could give a fault, but it isn't)
'''
import tkinter as tk
from tkinter import filedialog
from pathlib import Path
import zipfile
import os
import json
import requests
root = tk.Tk()
root.withdraw()
file_path = filedialog.askdirectory()
os.chdir(file_path)
def _walk(path: Path) -> []:
all_files = []
for x in path.iterdir():
if x.is_dir():
all_files.extend(_walk(x))
else:
all_files.append(x)
return all_files
def zip_files(path: Path, archive_name: str):
all_files = _walk(path)
with zipfile.ZipFile(f'{archive_name}', 'w', zipfile.ZIP_DEFLATED) as zipf:
for f in all_files:
zipf.write(f)
zipf.close()
def zip_this_folder():
print('compressing...')
zip_files(Path.cwd(), 'myzipfile.zip')
print('...compression done!')
if __name__ == "__main__":
zip_this_folder()
'''