Thread: Scanning all directories on a computer for a certain file

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    1

    Scanning all directories on a computer for a certain file

    I'm creating my own type of file search and I wanted to know if theres a simple method to using the dir.h and dirent.h to search and scan the working directory and attempt to search the entire computer for a file name or file type. Thanks!
    p.s. I'm trying to put this all in one function so I can return the full path of the file. I'm guessing it would be like using recursion? I'm not sure how to approach this.
    Last edited by Skyxnet; 07-26-2007 at 04:13 PM.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    It can be implemented recursively, but you can just as well do it iteratively, you just have to use some sort of stack data structure to "remember where you need to go back to" when you walk down directory structures. There's probably little difference between the implementations in regards to performance, it's more a question of style - and of course, if you have a limited stack-size (say in a mobile phone OS), you may not want to use recursion if the data-structures on the stack are large - which pathnames can be.

    Of course, you don't really need to write such an application. In Linux/Unix, you have "find", and in Windows you can use "dir somefile-to-look-for /s/b" to give you the exact thing you're describing. (And if you don't know EXACTLY what the file is called, you can use wildcards to specify part of the name).

    --
    Mats

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. Basic text file encoder
    By Abda92 in forum C Programming
    Replies: 15
    Last Post: 05-22-2007, 01:19 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM