954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

open a folder in graphical mode using c++ and linux os

hi
hope anyone who reads this post is doing well/will be doing well soon enough :) ...
i have a small problem... i have a program in c/c++ (i am using just a few functions of c++) which creates a log of files after doing some search(its not relavent to the question )...called files.txt... and then creates symbolic links for the files in the files.txt in a folder called results...

currently i am printing a statement which says..."please open results folder to view files found."...

i want to know is there a way by which i can open the result folder from the program i.e. result folder in a window with files/links to files as icon ...
I am using linux os... i can use c/c++ if c doesn't support the solution...

bilalb1
Newbie Poster
18 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

Yes, call opendir() the readdir(). A complete workable example program is in the Code Snippets

>>i am using just a few functions of c++

That makes it a c++ program, not a c program.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

thanks for the reply...

bilalb1
Newbie Poster
18 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

ok i don't know how that code works but anyhow your solution did gave me an idea..which was to post this question on some linux forum... i did get the reply ....for that and the solution is only one line just execute the command on linux shell e.g.
system("konqueror /path/foldername");
for interest of the reader here is the link

http://www.linuxforums.org/forum/misc/101818-how-open-folder-graphical-mode-window-using-linux-shell.html#post501287


p.s. i am not saying your solution is bad(i don't think it is the solution i was looking for i mean the code snippet isn't) i am just trying to help anyone else who might view this post...

i think this solution is not too complex and easy to understand for people who are newbies like me and are only need it work on KDE...

bilalb1
Newbie Poster
18 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

i don't mean to offend you dragon if i did i am very sorry...

bilalb1
Newbie Poster
18 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

I don't know what this "opening a folder" exactly supposed to mean, but one thing which is usually always available, no matter what desktop you use, is xterm. This opens xterm in the directory /pathname/foldername and prints the directory contents:

system ("xterm -e 'cd /pathname/foldername && ls && bash'");

Then you can do everything with the files in that directory.

TkTkorrovi
Junior Poster
170 posts since Mar 2005
Reputation Points: 85
Solved Threads: 13
 
i don't mean to offend you dragon if i did i am very sorry...

No offense taken and no need for apology. The solution I posted will get you all the files in the directory and all sub-directories and puts the file names in a std::vector. Might be a little too complicated for new programmers though.

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

hey ancient sorry for not replying it did get it solve eventually... with a bit of editing...

bilalb1
Newbie Poster
18 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

HI I THINK I GOT YOUR PROBLEM SOLVED.

YOU CAN USE THE BELOW PROGRAM TO DISPLAY THE CONTENTS OF FOLDER IN AN ARRAY.

THIS WORKS IN LINUX

#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

/*function... might want it in some class?*/
int getdir (string dir, vector<string> &files)
{
    DIR *dp;
    struct dirent *dirp;
    if((dp  = opendir(dir.c_str())) == NULL) {
        cout << "Error(" << errno << ") opening " << dir << endl;
        return errno;
    }

    while ((dirp = readdir(dp)) != NULL) {
        files.push_back(string(dirp->d_name));
    }
    closedir(dp);
    return 0;
}

int main()
{
    string dir = string(".");
    vector<string> files = vector<string>();

    getdir(dir,files);

    for (unsigned int i = 0;i < files.size();i++) {
        cout << files[i] << endl;
    }
    return 0;
}
smvinothkumar
Newbie Poster
4 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
 

Nice going -- but you are three years too late :)

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You