dagg
11/14/2014 - 10:28 AM

Check if something is file or dir with python

Check if something is file or dir with python

import os

x = os.listdir('.') #list of files in current dir 

for i in x:
    if os.path.isdir(i):
            print i, 'is dir'                                                                                                                                      
    if os.path.isfile(i):                                                                                                                                           
            print i, 'is file'