My very first Python script : DocFinder

As you may already have noticed, I am quite found of Python as a programming language.

I fell in love with Python some years ago, but you should know more about this soon icon smile My very first Python script : DocFinder .

As many of Python users, I started with Dive into Python (moreover its french translation).

Some days ago, I found myself into the very first Python script I ever written (but still use some times icon smile My very first Python script : DocFinder ). I found it funny (even more when you think that It can be reduced to a one-liner), and thought I would share it.

It aims at listing all documents from a given extension in a folder. To use it, simply run


$ docfinder folder extension

So here is the code :

#!/usr/bin/python
#_*_ coding: ISO-8859-15 _*_
import os
import sys

def scan_rep(repertoir, extension):
    """scanne le rep courant pour trouver des tex"""
    for racine, reps, fichiers in os.walk(repertoir, topdown=True):
        for fichier in fichiers:
            if fichier.endswith('.%s' % extension):
                nom_complet=os.path.join(racine, fichier)
                print '%s '%\(nom_complet)
if __name__=='__main__':
    scan_rep(sys.argv[1],sys.argv[2])

Pretty lame, isn’t it ? icon smile My very first Python script : DocFinder

When you find yourself a bad programmer, it is always good to look at the past and see that you actually made some progress icon smile My very first Python script : DocFinder .

You might want to check my current pet project, it is also all Python icon smile My very first Python script : DocFinder

Julien

Similar Posts:

flattr this!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>