Arik Baratz wrote:

On Apr 7, 2005 3:44 PM, Noam Meltzer <[EMAIL PROTECTED]> wrote:


Hi,
I remember I once encounted a utility which can print a formatted
output of the directory tree.
But can't find it now.



Hi Noam

There's a package named tree on my Mandrake installation, but I mainly
use a Python routine which I customize to my heart's content.

-- Arik

#!/usr/bin/env python

import os,sys,stat

def Crawl(sFolder,sIndent=""):
   "crawl a folder"

   lFiles=os.listdir(sFolder)

for sFile in lFiles:
sAbsFile=os.path.join(sFolder,sFile)
try:
tStat=os.stat(sAbsFile)
except OSError:
print 'Cannot stat file %s' % sAbsFile
continue
nMode=tStat[stat.ST_MODE]
if stat.S_ISDIR(nMode):
print "%s%s/" % (sIndent,sFile)
Crawl(sAbsFile,sIndent+" ")
else:
print "%s%s" % (sIndent,sFile)


def main():
   if len(sys.argv)>1:
       sFolder=sys.argv[1]
   else:
       sFolder=os.getcwd()
   Crawl(sFolder)

if __name__ == '__main__':
main()


10x all for answering.
It was very helpful :)

Noam

=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]



Reply via email to