Thread: Re-writing ls -F in C++

  1. #1
    Unregistered
    Guest

    Question Re-writing ls -F in C++

    ...on a Unix box.

    As the subject states, I am re-writing the ls -F command in C++, but I am having trouble adding some of the Formatting characters to the files names. Here is my code:

    Code:
     if (strcmp(buff, "-F")==0)
      {
         struct stat s;
         stat(direntp->d_name,&s);
         cout<<direntp->d_name;
         if(s.st_mode & S_IFDIR)
              cout<<"/"<<endl;
       else
         if(s.st_mode & S_IFIFO)
             cout<<"|"<<endl;
       else
         if(s.st_mode & S_IFLNK)
             cout<<" "<<endl;
       else
         if(s.st_mode & S_IFDOOR)
             cout<<">"<<endl;
       else
         if(s.st_mode & S_IFSOCK)
             cout<<"="<<endl;
       else
         if((s.st_mode & S_IXUSR) && (s.st_mode & S_IFLNK))
               cout<<"*"<<endl;
         else
           cout<<"?"<<endl;
      }//end if
    It is adding the correct formatting character ("/") for directories, but not for my execuatble files such as "a.out" and "paige_sh" which should have an asterick (*). Here is a sample run:

    Code:
    mars:$ a.out
    -F
    ./
    ../
    shell1.cpp
    env.c
    core
    
    a.out
    modshell2.1.cpp
    read_command
    shell.sh
    shell
    test.sh
    ansipr
    shell2.c.save
    paige_sh
    modshell1.2.cpp
    modshell1.3.cpp
    gid.c
    modshell2.3.cpp
    1814shell.cpp
    cpplist
    uid.c
    listfile.txt
    listDir.cpp
    modshell2.cpp
    modshell2.2.cpp
    rewritels.cpp
    writels2.cpp
    justafile.txt
    justafile2.txt
    justadir/
    justadir2/
    can anyone help?? Thanks.

  2. #2
    Unregistered
    Guest
    never mind...fixed it myself

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-20-2008, 08:57 AM
  2. version of ls -l bug, only takes cwd :(
    By chl12 in forum C Programming
    Replies: 2
    Last Post: 06-12-2007, 02:44 AM
  3. Very slow file writing of 'fwrite' function in C
    By scho in forum C Programming
    Replies: 6
    Last Post: 08-03-2006, 02:16 PM
  4. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 08:44 AM
  5. help! fifo read problem
    By judoman in forum C Programming
    Replies: 1
    Last Post: 08-16-2004, 09:19 AM