Linux, Python, ProgramaciónMarch 2, 2007 10:28 am
Busqueda Recursiva en Python
Este es un pequeño script que hice para realizar una busqueda de archivos de forma recursiva, A pedido de un compañero, Espero les sirva.
import os
def search(path,file_name):
try:
files = os.listdir(path)
trunk = 0
except OSError:
print “Access Denied: ” + path
trunk = 1
if trunk == 0:
for f in files:
if os.path.isdir(path + f):
search(path + f + ‘/’,file_name)
else:
if file_name == f:
print ‘Found : ‘ + path + f
if __name__ == ‘__main__’:
path = raw_input(”Directorio de busqueda: “)
file = raw_input(”Archivo a buscar: “)
search(path,file)
|
The URI to TrackBack this entry is: http://nachxs.blogsome.com/2007/03/02/busqueda-recursiva-en-python/trackback/
No comments yet.
RSS feed for comments on this post.
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>