Here is the code:
import os
def main(folder_path):
get_files_from_folder(folder_path)
def remove_file(dir:str):
"""
This method is used to delete a single file if it exists.
"""
if os.path.exists(dir):
os.remove(dir)
def get_files_from_folder(folder_path:str):
"""
This method is used to delete the file in a folder.
"""
if os.path.exists(folder_path):
for files in os.listdir(folder_path):
file_path = os.path.join(folder_path, files)
remove_file(file_path)
if _name_ == '__main__':
folder_path = "C:\\Users\\Emanuel\\Downloads\\Test Folder\\Delete Files"
main(folder_path)import os
def main(folder_path):
get_files_from_folder(folder_path)
def remove_file(dir:str):
"""
This method is use to delete a single file if it exists.
"""
if os.path.exists(dir):
os.remove(dir)
def get_files_from_folder(folder_path:str):
"""
This method is use delete the file in a folder.
"""
if os.path.exists(folder_path):
for files in os.listdir(folder_path):
file_path = os.path.join(folder_path, files)
remove_file(file_path)
if _name_ == '__main__':
folder_path = "C:\\Users\\Emanuel\\Downloads\\Test Folder\\Delete Files"
main(folder_path)
#python #automation
Watch video Remove / Delete Files Python - Automation online without registration, duration hours minute second in high quality. This video was added by user TheBouncingPixel 16 June 2022, don't forget to share it with your friends and acquaintances, it has been viewed on our site 181 once and liked it 2 people.