Thread: directory listing

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    36

    directory listing

    i have the follwing code to list the files in a directory.........but i need the name of the files which doesnt have any extensions
    for e.g.
    if my directory containts the following files:
    a
    gg
    1.txt
    code.c

    i need only "a" and "gg"

    this is "C" in linux
    Code:
    chdir(dir);
        while((entry = readdir(dp)) != NULL) {
            
           lstat(entry->d_name,&statbuf);
           
     if(S_ISDIR(statbuf.st_mode)) {
                
                if(strcmp(".",entry->d_name) == 0 || 
                    strcmp("..",entry->d_name) == 0)
                    continue;
                printf("%*s%s/\n",depth,"",entry->d_name);
                printdir(entry->d_name,depth+4);
            }
            else
              printf("%s\n",entry->d_name);
    thanx
    Last edited by warney_out; 02-01-2005 at 10:25 PM.

  2. #2
    Registered User
    Join Date
    Mar 2004
    Posts
    494
    use code tags to make your code readable. Im sure every peice of code you have seen its formated correctly.
    When no one helps you out. Call google();

  3. #3
    Unregistered User
    Join Date
    Nov 2004
    Posts
    25
    Something like this:
    Code:
    if (strchr (entry->d_name, '.') == NULL)
        printf ("%*s%s/\n",depth,"",entry->d_name);
    ??
    Last edited by frrossk; 02-02-2005 at 01:20 AM.

  4. #4
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Is you strcmp "." perhaps picking up the . in the filename and giving you issues?
    Demonographic rhinology is not the only possible outcome, but why take the chance

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  2. Listing specific files in a directory
    By knirirr in forum C Programming
    Replies: 14
    Last Post: 01-29-2008, 05:42 AM
  3. Replies: 4
    Last Post: 06-05-2006, 03:24 AM
  4. recursive directory listing help
    By laney69er in forum C Programming
    Replies: 2
    Last Post: 03-13-2006, 01:07 PM
  5. Directory listing
    By brif in forum C++ Programming
    Replies: 1
    Last Post: 10-10-2002, 06:44 AM