Answer the question
In order to leave comments, you need to log in
How to find executable files in ubuntu in C++?
Good evening. Can you tell me how to find all the files in the directory that are executable in C ++ in Ubuntu?
Here is the code:
#include <stdio.h>
#include <dirent.h>
#include <string.h>
int main(int argc, char **argv)
{
struct dirent *DirEntry;
unsigned char isFile =0x8;
DIR *dfd;
struct dirent *dp;
char filename[NAME_MAX];
if ( argc < 2 )
strcpy(filename, ".");
else
strcpy(filename, argv[1]);
printf("%s\n\n", filename);
dfd=opendir(filename);
while((dp=readdir(dfd)) != NULL )
{
if(dp->d_type == isFile)
printf("%s\n", dp->d_name);
}
closedir(dfd);
return 0;
}
Answer the question
In order to leave comments, you need to log in
stackoverflow.com/questions/5719694/having-a-path-...
#include <sys/stat.h>
bool can_exec(const char *file)
{
struct stat st;
if (stat(file, &st) < 0)
return false;
if ((st.st_mode & S_IEXEC) != 0)
return true;
return false;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question