By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,857 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,857 IT Pros & Developers. It's quick & easy.

About checking executable files

P: n/a
mhk
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

Nov 13 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Nov 13 '05 #2

P: n/a
mhk <cc*****@dddsssl.com> 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
Nov 13 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.