I've read a lot of questions with this issue, but I've noticed that it happens for many many reasons, and haven't found an answer to my particular problem. The thing is, I've accidentally deleted some files and used photorec to try and recover them (I'm on Ubuntu 16.04 Xenial). The problem is, it recovered 2600+ folders! I'm writing a little filecrawler to get rid of the files I don't need - the only files that interest me are .py,.jpg,.png and .mp3. Here is the code to my crawler:
import os
path=
for (path, dirs, files) in os.walk(path):
for name in files:
if name.endswith('.py') or name.endswith('.jpg') or name.endswith('.png') or name.endswith('.mp3'):
continue
else: os.remove(name)
I define 'path' manually, and I've done a test where I print part of the paths,dirs and files, and it prints what I want. However, when running the code below, it returns:
OSError: [Errno 2] No such file or directory: 'f0272560.java'
Which I'm assuming is the first file I try to remove. I'm guessing that it is looking for the file again, after it was deleted already. Does this have sense or it is anything else raising the error? How could I fix this?
Thanks in advance!