guard against files without extensions and directories outside source_dir
as per @just-boris's suggestions