Is there a function to search the HD

Discussion in 'Python' started by Peter Jensen, Sep 28, 2004.

  1. Peter Jensen

    Peter Jensen Guest

    Hi all.

    I was wondering if there is an inbuild function in python to search your
    harddrives ( Harddisk's) for a file of a speciel type. I mean can I write a
    command with 2 parameters ( one being the filetype, and the other the
    location on the harddisk where I want to search for the specific file type )

    Thank for all input...
     
    Peter Jensen, Sep 28, 2004
    #1
    1. Advertising

  2. Peter Jensen

    Max M Guest

    Peter Jensen wrote:
    > Hi all.
    >
    > I was wondering if there is an inbuild function in python to search your
    > harddrives ( Harddisk's) for a file of a speciel type. I mean can I write a
    > command with 2 parameters ( one being the filetype, and the other the
    > location on the harddisk where I want to search for the specific file type )
    >
    > Thank for all input...



    6.1 os -- Miscellaneous operating system interfaces

    This module provides a more portable way of using operating system
    dependent functionality than importing a operating system dependent
    built-in module like posix or nt.

    6.1.4 Files and Directories

    walk( top[, topdown=True [, onerror=None]])

    walk() generates the file names in a directory tree, by walking the tree
    either top down or bottom up. For each directory in the tree rooted at
    directory top (including top itself), it yields a 3-tuple (dirpath,
    dirnames, filenames).


    --

    hilsen/regards Max M, Denmark

    http://www.mxm.dk/
    IT's Mad Science
     
    Max M, Sep 28, 2004
    #2
    1. Advertising

  3. On Tue, 28 Sep 2004 10:37:07 +0200, Peter Jensen <> wrote:
    > I was wondering if there is an inbuild function in python to search your
    > harddrives ( Harddisk's) for a file of a speciel type. I mean can I write a
    > command with 2 parameters ( one being the filetype, and the other the
    > location on the harddisk where I want to search for the specific file type )


    You want os.walk(). There's a simple example of its use here:

    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/279003

    --
    Cheers,
    Simon B,
    ,
    http://www.brunningonline.net/simon/blog/
     
    Simon Brunning, Sep 28, 2004
    #3
  4. On Tue, 28 Sep 2004 10:37:07 +0200, Peter Jensen wrote:

    > I was wondering if there is an inbuild function in python to search your
    > harddrives ( Harddisk's) for a file of a speciel type. I mean can I write
    > a command with 2 parameters ( one being the filetype, and the other the
    > location on the harddisk where I want to search for the specific file type
    > )


    On Unix, you may want to call locate to do the searching. This is a lot
    faster than walking the file system yourself. You can use os.system to
    call locate (see man locate for details).

    Jeremy
     
    Jeremy Sanders, Sep 28, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=

    Google search result like site search!! How?

    =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    716
    Lucas Tam
    May 6, 2005
  2. Andy
    Replies:
    1
    Views:
    376
    Jack Klein
    Nov 25, 2003
  3. Replies:
    2
    Views:
    972
    Bengt Richter
    Aug 1, 2005
  4. Abby Lee
    Replies:
    5
    Views:
    482
    Abby Lee
    Aug 2, 2004
  5. Replies:
    5
    Views:
    227
    Randy Kobes
    Oct 12, 2005
Loading...

Share This Page