Shubham Deswal
Shubham Deswal

Reputation: 75

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")

    else:

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

Upvotes: 0

Views: 1229

Answers (1)

moken
moken

Reputation: 6630

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

Upvotes: 2

Related Questions