Thread: Browsing directory in unix

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

    Browsing directory in unix

    Hi, I am looking for a C program in Unix to browse the directory and list the files(recursively). Can somebody help me on this.
    Thanks in advance.
    Jaykar

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    int main()
    {
       system("ls -Lr");
       return 0;
    }
    any good?

    Seriously, you want to look at "opendir()" and "readdir()" and "closedir()". You'll probably need "stat" as well to get some of the data about the file, if you want to show more than the filename.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Or even just read the FAQ.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  3. Directory browsing
    By earth_angel in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2005, 08:37 AM
  4. Open files inside directory (UNIX platform)
    By swagatob in forum C Programming
    Replies: 15
    Last Post: 10-25-2004, 12:58 AM
  5. Replies: 6
    Last Post: 07-30-2003, 03:08 AM