I'm trying to read all files (pictures) in a given directory and pass it to execv. I want to start the framebuffer image viewer (fbi).
For now it works when i start it from the directory the pictures are in. How can i manipulate the vector so it not only holds the filenames but the path + filename?
int startSlideshow (char* pathtoFBI) {
pid_t fbiPid;
fbiPid = fork();
if (fbiPid == 0) {
/* this is the child process */
DIR *pictureDirectory;
struct dirent *dir;
int i = 0;
vector<char*> argVector;
char pDirectory[] = "/home/pi/bilder/";
argVector.push_back(pathtoFBI); /* first Argument is Program name */
pictureDirectory = opendir(pDirectory);
if (pictureDirectory){
while ((dir = readdir(pictureDirectory)) != NULL) {
i++;
if (i > 2) { /* first element is "." second is ".." */
argVector.push_back(dir->d_name);
}
}
//i -= 2;
} else ERREXIT("reading picture directory");
closedir(pictureDirectory);
argVector.push_back(NULL);
char** fbiArgv = &argVector[0];
execvp(pathtoFBI, fbiArgv); /* pid is taken over by fbi */
_exit(EXIT_FAILURE);
}