the 2nd time you use dir(), you don't specify you want only files... (or, alternatively, you don't check if it's a directory before you print it...)