The Directory Lister

posted: Mon, 02 Jul 2007 23:40 | filed under: / / / | permalink | Comments: 1

Well, it seems as though it's impossible to go through a life of coding without writing a directory lister... So in the great tradition of this site, I give you my directory lister -- It spits out the entirety of your directory structure, either starting at the current dir, or at some specified one. It spits it out in a format suitable for grepping on a Unix system, as for some reason, the Unix

ls
tool doesn't do so.

Here's the code in it's entirety -- written in python, under the terms of the GPLv2 or later

#!/usr/bin/env python

import os
import sys
if len(sys.argv) == 1:
	k = "."
else:
	k = sys.argv[1]

for dr,drs,fls in os.walk(k):
	for i in fls:
		print dr+"/"+i
	for i in drs:
		print dr+"/"+i

May someone find it useful

Comments

Yours has to be compiled from source :P.

On the up side, yours doesn't compile to a 700KiB behemoth.

Posted by Jack Scott at Tue Jul 3 17:35:23 2007


Leave a comment

Name:


E-mail:


URL: (Prefix with http://)


Comment: