showing whats in folder

This is a discussion on showing whats in folder within the C Programming forums, part of the General Programming Boards category; hello there, i was wondering maybe anyone have any example of code, which would show the content of a folder, ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    14

    showing whats in folder

    hello there, i was wondering maybe anyone have any example of code, which would show the content of a folder, which path u enter? like i enter the path to the folder and then it prints everything, that's in the folder?
    Last edited by apisio; 11-21-2009 at 05:39 AM.

  2. #2
    Registered User
    Join Date
    Nov 2009
    Posts
    14
    btw, i'm just working with console application.. :P

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    21
    Make some system calls.

    Example:

    Code:
         #include <stdio.h>
         #include <sys/types.h>
         #include <dirent.h>
         
         int
         main (void)
         {
           DIR *dp;
           struct dirent *ep;
         
           dp = opendir ("./");
           if (dp != NULL)
             {
               while (ep = readdir (dp))
                 puts (ep->d_name);
               (void) closedir (dp);
             }
           else
             perror ("Couldn't open the directory");
         
           return 0;
         }
    Simple Directory Lister - The GNU C Library

  4. #4
    Registered User
    Join Date
    Nov 2009
    Posts
    14
    Thank you, seaking1. This is perfect example for me. how can i change the directory? is it this *dp one?

  5. #5
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    The dp = opendir ("./"); is where the starting directory is named.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading .dat files from a folder in current directory...
    By porsche911nfs in forum C++ Programming
    Replies: 7
    Last Post: 04-04-2009, 09:52 PM
  2. accessing all files in a folder.
    By pastitprogram in forum C++ Programming
    Replies: 15
    Last Post: 04-30-2008, 10:56 AM
  3. Not able to access directory of home folder
    By Bargi in forum Linux Programming
    Replies: 1
    Last Post: 02-06-2008, 01:45 AM
  4. read only folder on Windows
    By George2 in forum Windows Programming
    Replies: 2
    Last Post: 11-05-2007, 08:18 AM
  5. Hiding a folder
    By nextstep in forum Windows Programming
    Replies: 16
    Last Post: 03-20-2005, 02:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21