user7192474
user7192474

Reputation:

Recovering a file deleted with python

So, I deleted a file using python. I can't find it in my recycling bin. Is there a way I can undo it or something. Thanks in advance.

EDIT: I used os.remove. I have tried Recuva, but it doesn't seem to find anything. I have done a deep search.

Upvotes: 6

Views: 22509

Answers (2)

Vali Izzatullayev
Vali Izzatullayev

Reputation: 21

If you deleted the file using PyCharm IDE then it is possible. It says:

Restore deleted files

If you've accidentally deleted a file that was not under version control, you can restore it with Local History.

  1. Select the node that contained the file you deleted in the Project tool window, right-click it and choose Local History | Show History from the context menu.

  2. On the left, select the revision that contains the file you want to restore, right-click that file, and choose Revert Selection.

Upvotes: 2

Jérôme
Jérôme

Reputation: 14714

If you used os.remove and ended up deleting a file by accident, then there's no reason for this file to be in the recycle bin. It is removed from the filesystem. There is no Python operation to get that file back.

However, a simple deletion just breaks the link to the file but does not erase the bits of the file on the filesystem. You can try file recovery softwares to get it back.

Note that

  • Now that the file is erased, this question is not Python specific anymore. You'd be in the same situation if you had deleted the file by any other means.

  • You should avoid using your system to minimize the chances of erasing the bits of the file by writing another file at the same place on the disk.

  • The tools you can use to recover the file are platform specific and the generic question "how to recover deleted files" has most certainly already been asked here, on Super User, Unix & Linux, or some other Stack Exchange community.

Upvotes: 13

Related Questions