How to restore files that are deleted by os.remove function in python?

I am just writing a python code to delete files older than 30 days. While running it, Unfortunately, I gave the wrong path and some of my precious data was deleted.

Can you please tell me how can I restore that data?

This is the function that I used

def remove_file(path):

    # removing the file
    if not os.remove(path):

        # success message
        print(f"{path} is removed successfully")


        # failure message
        print(f"Unable to delete the {path}")

>Solution :

There are python modules that allow safe deletion like ‘send2trash’. You could then recover the files from the recycle bin or trash

Leave a Reply