About checking executable files

Discussion in 'C Programming' started by mhk, Nov 4, 2003.

  1. mhk

    mhk Guest

    Hi ,

    i am writing a c language program in Unix to see the executable files in
    a directory and it works if the directory is current but if i change to
    another directory than current directory then it show all the files even
    if not executable.

    here is the main code

    while (p = readdir(dp))
    {
    stat(p->d_name, &s);

    if (strcmp( p->d_name,".")!= 0 && strcmp( p->d_name,"..")!= 0 )
    {
    if (s.st_mode & S_IXUSR)
    {
    cc = ctime(&s.st_mtime);
    printf("%s| %s \n", p->d_name, cc);
    }
    }
    }

    can anyone help?

    Thanks alot.

    Jeff
     
    mhk, Nov 4, 2003
    #1
    1. Advertising

  2. mhk

    pete Guest

    mhk wrote:
    >
    > Hi ,
    >
    > i am writing a c language program in Unix


    > while (p = readdir(dp))


    Try
    news:comp.unix.programmer

    readdir isn't a standard C library function.

    --
    pete
     
    pete, Nov 4, 2003
    #2
    1. Advertising

  3. mhk

    Derk Gwen Guest

    mhk <> wrote:
    # Hi ,
    #
    # i am writing a c language program in Unix to see the executable files in
    # a directory and it works if the directory is current but if i change to
    # another directory than current directory then it show all the files even
    # if not executable.
    #
    # here is the main code
    #
    # while (p = readdir(dp))

    Returns the path relative to the directory being read. Unless that
    is the current directory, you're looking for files in the wrong
    directory. You have to prefix the directory path to d_name.

    # stat(p->d_name, &s);

    If you checked the return value and errno of stat, it would be telling
    you you've got nonexistent files.

    --
    Derk Gwen http://derkgwen.250free.com/html/index.html
    Why are we here?
    whrp
     
    Derk Gwen, Nov 5, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    1,507
    Malte
    Mar 9, 2005
  2. Replies:
    15
    Views:
    491
    Dave Thompson
    Aug 21, 2006
  3. pratap
    Replies:
    20
    Views:
    760
    Flash Gordon
    Mar 7, 2007
  4. Jason Cavett
    Replies:
    8
    Views:
    622
    Sanjay
    May 16, 2007
  5. Replies:
    0
    Views:
    443
Loading...

Share This Page