Python Programming 101 - Capstone Project | Zero Byte File Automation

Python Programming 101 - Capstone Project | Zero Byte File Automation

Python Programming 101 - Capstone Project | Zero Byte File Automation
Python Programming Capstone Project

Hi Guys,

Today we are developing our first capstone project Zero Byte File Automation program.

Check out the complete code here.

What does this program do?

It searches deep dive in the file and folders of our system and lists out only that file which of size
Zero Bytes and deletes them.

Does this program user-friendly?

Yes, the zero-byte file searching automation project is very structured and user-friendly. User-friendly means to say it will prompt the user every time when it is about to take any critical steps such as deletion etc.

What are the major functions of this project?


The Project has four major functions :
  1. Searching for file: First, we need to pass the directory or drive location where we want to proceed the searching for a file. Location is a mandatory field.
  2. Asking for backup: Once the search completes, the program will ask for taking backup of all those files into a separate directory. Why backup is important? Sometimes file name is important for setup or executable file. 
  3. Asking for deletion: If you want to delete the files Press Yes or No. 
  4. Message display: Once the deletion is successful, it will display a message. 

Code Explanation:


Below is the project teardown:

    1. Input file where you want to walkthrough (search the number of zero bytes files) whole path.
    2. Paste the file path and filename in excel. 
    3. prompt the user to take backup either yes or no. 
    4. prompt the user to delete all files or select either of the files. 
    5. Display the message file deleted.

Below are the modules used in the project:

  1. Python OS Module (Used for operating system related task)
  2. Python Openpyxl (Used for excel manipulation task)
  3. Python Shutil (Used for file manipulation task)

Below are the functions used in the project:

This function is used for entering the file path where we want to search the zero size file.

def filePath():
        filepath = input('Enter the path you want to search for zero byte : ')
        print("\n")
        return filepath


This function saves the backup into an excel file. 



def search_save_excel(filepath):
        wb = openpyxl.load_workbook("ZeroByteFileList.xlsx")
        ws = wb.get_sheet_by_name('Sheet1')
        file = []
        filename = []
        global backup_del
        count = 0
        for folder,subfolder,filenames in os.walk(filepath):
            for k in filenames:
                if (os.path.getsize(os.path.join(folder,k))) == 0 :
                    file.append(folder)
                    filename.append(k)
                    backup_del.append(os.path.join(folder,k))
                    count += 1
        for i, files in enumerate(file):
               ws.cell(row=i+1, column=1).value = files
        for i, filenames in enumerate(filename):
               ws.cell(row=i+1, column=2).value = filenames
        wb.save('ZeroByteFileList.xlsx')
        print("Total files present in path ",filepath," of zero byte are : ",count)



This function backup the file and for this, we need to enter the specified directory.



def backup(backup_del):    
    backupPath = input('Enter the path where you want to store all backup files : ')
    print(len(backup_del))
    for i in backup_del:
        shutil.copy(i,backupPath) 
        print('\n')



This function deletes the file and after deletion displays the message for successful deletion.


def delete(backup_del):
            for i in backup_del:
                os.unlink(i)
            message()

def message():
        print("*********************************")
        print("***Files Successfully deleted.***")
        print("*********************************")



The main function is responsible for calling all the related methods such as file deletion, backup, and displaying the message.


def main():
    search_save_excel(filePath())
    print('\nBefore proceeding deletion want to take back up of all files (Yes or No) ')
    print("****************************************************************************")
    Ans = input('Y/N ')
    if (Ans.lower() == 'y') or (Ans.lower() == 'yes'):
            print("**********")
            print("**BACKUP**")
            print("**********")
            backup(backup_del)
    delinp = input("Want to delete the file ? [Y/N] ")
    if (delinp.lower() == 'y') or (delinp.lower() == 'yes'):
            print("**********")
            print("**Delete**")
            print("**********")
            delete(backup_del)
    else:
        print("No FILES DELETED !!!!")
print("*********************************")
print("Zero Byte File Search Automation")
print("*********************************")
ans = input('Want to Proceed (Yes or No) ')
print("*********************************")
if (ans.lower() == 'y') or (ans.lower() == 'yes'):
        main()
        del backup_del
else:
        print("No FILES DELETED !!!!")
        del backup_del



Code available in Github repo. Click here.  

Python Programming related tutorial. Click here.

For Complete Python Programming 101 tutorial series ( Click here ). 

For Queries and Contact there are multiple ways:

1. From telegram search @randomskoolQnA and @randomskool 
2. From Contact Us Page
3. From Comment 

For Daily Updates Please subscribe to the feed. 

For Job-related Updates Please fill the subscriber feedback form.

Join our telegram channel and group :)

Telegram Group: https://t.me/randomskoolQnA
Telegram Channel: https://t.me/randomskool

Till then happy coding !!!






1 Response to "Python Programming 101 - Capstone Project | Zero Byte File Automation"

  1. Thanks, this is generally helpful.
    Still, I followed step-by-step your method in this Python Online Training
    Python Online Course

    ReplyDelete

Hey Random,

Please let me know if you have any query :)

Adsense

Adsense

Adsense

Adsense