Revert: Using my old code

Check extension before file name, this could result in less loops.