#NEWLINE# def list_files( startpath ) : #NEWLINE# #INDENT# 'tree unix command replacement.' #NEWLINE# s = '\n' #NEWLINE# for ( root , dirs , files ) in os . walk ( startpath ) : #NEWLINE# #INDENT# level = root . replace ( startpath , '' ) . count ( os . sep ) #NEWLINE# indent = ( ( ' ' * 4 ) * f ) #NEWLINE# s += '{}{}/\n' . format ( indent , os . path . basename ( root ) ) #NEWLINE# subindent = ( ( ' ' * 4 ) * ( level + 1 ) ) #NEWLINE# for f in files : #NEWLINE# #INDENT# s += '{}{}\n' . format ( subindent , f ) #NEWLINE# #UNINDENT# #UNINDENT# return s