C Board  

Go Back   C Board > Platform Specific Boards > Linux Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-19-2002, 12:50 PM   #1
Unregistered
Guest
 
Posts: n/a
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.
  Reply With Quote
Old 03-21-2002, 08:39 AM   #2
Unregistered
Guest
 
Posts: n/a
never mind...fixed it myself
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
writing and appending to file lots of times takes to long how to improve ? umen242 C++ Programming 2 05-20-2008 08:57 AM
version of ls -l bug, only takes cwd :( chl12 C Programming 2 06-12-2007 02:44 AM
Very slow file writing of 'fwrite' function in C scho C Programming 6 08-03-2006 02:16 PM
Folding@Home Cboard team? jverkoey General Discussions 398 10-11-2005 08:44 AM
help! fifo read problem judoman C Programming 1 08-16-2004 09:19 AM


All times are GMT -6. The time now is 11:51 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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