Skip to content

Instantly share code, notes, and snippets.

@techedlaksh
Created May 17, 2017 20:22
Show Gist options
  • Save techedlaksh/2b5154696d84aeea3fba7e44c5165e18 to your computer and use it in GitHub Desktop.
Save techedlaksh/2b5154696d84aeea3fba7e44c5165e18 to your computer and use it in GitHub Desktop.
zipping the folder and changing the extension
import os
import shutil
from tkinter import Tk
from tkinter import filedialog
import zipfile
def select_folder():
root = Tk()
root.withdraw()
filepath = filedialog.askdirectory()
if os.path.exists(filepath):
return filepath
else:
print("Sorry, that path doesn't seem to exist.")
input_folder_path = select_folder()
print("your input folder is:", input_folder_path)
output_folder_path = select_folder()
print("your output folder is:", output_folder_path)
ind = input_folder_path.rfind('/')
base_dir = input_folder_path[:ind+1]
zip_name = input_folder_path[ind+1:]
shutil.make_archive(zip_name, 'zip', input_folder_path)
shutil.move(base_dir + zip_name +'.zip', output_folder_path)
os.rename(output_folder_path + '/' + zip_name +'.zip', output_folder_path + '/' + zip_name + '.ava')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment