Thread: Simple version of find in C

  1. #1
    Registered User
    Join Date
    Oct 2013
    Posts
    11

    Simple version of find in C

    Just wondering about how to write extremely simple version of 'find' in C: It just lists the path names of the files in the specified directories and all subdirectories.For example,


    Code:
    $find_version .
        ./foo
        ./bar
        ./baz
        ./baz/other
        
        $find_version
        foo
        bar
        baz
        baz/other

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    I can't really help you with "wondering". What have you tried, what are you stuck on. You need to post some code, and explain the problem.

    Get into the game, instead of sitting on the sidelines.

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You would have to talk to your operating system (and thus you would have to use operating-system-specific function calls, ie FindNextFile in Windows vs readdir on *nix).

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Sounds more like a simple/extended tree command than a find command.

    Show some work or expect to be ignored.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    <whisper>Don't mention the FAQ</whisper>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Salem View Post
    <whisper>Don't mention the FAQ</whisper>
    Wow, that FAQ code is very good; I might write the simple function I was thinking of writing that produces a list of file extensions in a directory.
    (I have been looking at various version control; and was thinking of making something to create a list for all files for use in a ignore file list.)

    Once, I get done with my paid work will likely do this.
    Thanks.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  7. #7
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    This is unix find. I would use opendir and readdir

    opendir(3): open directory - Linux man page

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple error i can't find /code
    By Alecroy in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2010, 01:00 PM
  2. can u find any bug in this simple code??
    By mgnidhi_3july in forum C Programming
    Replies: 25
    Last Post: 06-09-2010, 09:28 AM
  3. How do i find the gcc version i have?
    By g_p in forum C Programming
    Replies: 11
    Last Post: 05-11-2008, 12:34 PM
  4. map .find() simple question
    By l2u in forum C++ Programming
    Replies: 1
    Last Post: 03-05-2008, 01:15 PM
  5. find file version in DOS
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-15-2002, 01:04 PM

Tags for this Thread