#NEWLINE# def listdir( path , recursive = False , dirs_only = False , files_only = False , filter_func = None ) : #NEWLINE# #INDENT# path = abspth ( f ) #NEWLINE# all_contents = [ ] #NEWLINE# if ( not recursive ) : #NEWLINE# #INDENT# all_contents = os . listdir ( path ) #NEWLINE# all_contents = [ joinpths ( path , f ) for f in all_contents ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for ( root , dirs , files ) in os . walk ( path ) : #NEWLINE# #INDENT# for d in dirs : #NEWLINE# #INDENT# all_contents . append ( joinpths ( root , d ) ) #NEWLINE# #UNINDENT# for f in files : #NEWLINE# #INDENT# all_contents . append ( joinpths ( root , f ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if dirs_only : #NEWLINE# #INDENT# all_contents = [ f for f in all_contents if isdir ( f ) ] #NEWLINE# #UNINDENT# if files_only : #NEWLINE# #INDENT# all_contents = [ f for f in all_contents if isfile ( f ) ] #NEWLINE# #UNINDENT# if filter_func : #NEWLINE# #INDENT# all_contents = [ f for f in all_contents if filter_func ( f ) ] #NEWLINE# #UNINDENT# return all_contents