using os.remove() in os.walk() for loop returns FileNotFoundError

The files variable contain only the filenames. When trying to manipulate the files you have to add the full path:

for root, dirs, files in os.walk(base):
    for f in files:
        if regex.match(f):
            os.remove(os.path.join(root, f))

Leave a Comment