0

This is not important, only waste your time if you're bored!

So I'll start like any other question: I'm not that new to programming. In fact I have tried it several times and was victim of tutorial purgatory and too much project based learning with too little knowledge. I'm trying again with python. I have a question about variable naming because I want to build good habits. I built a program that unzipps files in one directory and puts them in another one. In that directory a folder named after the zip file is created and the content is being put into that. The variable is called folder_directory in the code. folder_directory could literally be anything. I really thought about it and I can't come up with a name. Here is some of the code:

zip_dir = config['DEFAULT']['Where_you_put_your_zipped_files']
unzip_dir = config['DEFAULT']['Where_they_go_after_unzipping']
extension = ".zip"
os.chdir(zip_dir) # change directory from working dir to dir with files

def unzipall():#unzips all the items in zip_dir
    for item in os.listdir(zip_dir): # loop through items in dir
        if item.endswith(extension): # check for ".zip" extension
            file_path = os.path.abspath(item) # get full path of files
            file_name = os.path.basename(os.path.splitext(file_path)[0])#removing the .zip extension and the path to the .zip file, so file_name is just the name of the folder
            folder_directory = unzip_dir + '\\' + file_name + '\\' #creating the name of the aim directory
            createFolder(folder_directory)#create a subfolder that is named after the zip file
            zip_ref = zipfile.ZipFile(file_path)
            zip_ref.extractall(folder_directory) # extract file to dir
            zip_ref.close() # close file
            os.remove(file_path) # delete zipped file

I have a watchdog running and an .ini file to config your dirs just if someone's interested. So that's my 'problem', Finn

P.S.: I'm using capital case,camel case and snake case without any logic behind. I should leave that habit behind and become a better person ;-)

0 Answers0