Program that can find a find a file for you ?

Peter..... helten0007 at yahoo.com
Wed Sep 29 10:00:41 EDT 2004


Hi again all.
I allmost did it, just need the line to run the program now, any ideas, my 
head hurts, cant think anymore..... Thanks for your help

import sys
import os.path
import os.dir
a = sys.argv[2]
b = sys.argv[3]

def func (bib, end):
   c = os.path.dirlist(bib)

   for x in c:
   d = os.dir.split(x)
   if [1] = end
   print (bib, end)

if __name__=="__main__":





"Thomas Guettler" <guettli at thomas-guettler.de> wrote in message 
news:pan.2004.09.29.13.18.28.288793 at thomas-guettler.de...
> Am Wed, 29 Sep 2004 11:25:39 +0200 schrieb Peter Hansen:
>
>> Greetings.
>>
>> Im trying to write a program that can be run from the command line.
>> If I want to search for example after a file with the ending .pdf, I 
>> should
>> be able to write in the command line:
>> python  name of my program / the libary to search and what kind of file 
>> it
>> is example a .pdf file
>> So if my program name was test.py and the library name was library1 and 
>> the
>> test type i wanted to find was, a .pdf file
>> I should write python test.py /library1 .pdf
>
> Hi,
>
> This is something the "find" command does in a unix environment.
>
> Here is my solution:
>
> You could use this:
> find.py your_path 'library1.*\.pdf$'
>
> #!/usr/bin/env python
> # -*- coding: iso-8859-1 -*-
>
>
> # Python Imports
> import os
> import re
> import sys
>
> def usage():
>    print """Usage: %s path regex
> Print all files or directories with match the regex.
>
> See this URL for the syntax of the regular expressions
> http://docs.python.org/lib/re-syntax.html
>
>    """ % (os.path.basename(sys.argv[0]))
>
> def visit(regex, dirname, names):
>    for name in names:
>        p=os.path.join(dirname, name)
>        if regex.search(p):
>            print p
> def main():
>    if len(sys.argv)!=3:
>        usage()
>        sys.exit(1)
>    path=sys.argv[1]
>    regex=sys.argv[2]
>    os.chdir(path)
>    regex=re.compile(regex)
>    os.path.walk(".", visit, regex)
>
> if __name__=="__main__":
>    main()
> 





More information about the Python-list mailing list