You can exclude directories by checking if each entry is a file or a directory using os.path.isdir().