How to get system information

Hi All,

Ihave a simple problem but I could not think of a reasonable solution.

I’d like to have a simple algorithm to get system information like the current directory, list of files (not only root files). I can do it if I use gSystem with the “exec” method. But then there is a problem to port the code.

For example. I can use simple commands as “ls” and “cd” in linux. But if I decide
to run on windows I will need to come up with another version for it.

So…My doubt is:

Is there a simple way (portable) to get such information or I should implement it myself?

cheers,
Franciole

Hi Franciole,

Several user interface classes cover this need. You can simply create a TGFileDialog giving the option Open or Save and the contents of the current directory will be listed for user interactions (opening or saving file).
This class creates a file selection dialog. It contains a combo box for selecting the desired directory; a list view with the different files in the current directory and a combo box with which you can select a filter (on file extensions). When creating a file dialog a pointer to a TGFileInfo object has to be passed. In this object you can set the fFileTypes and fIniDir to specify the list of file types for the filter combo box and the initial directory. The selected file name can be found in the TGFileInfo::fFilename field and the selected directory in TGFileInfo::fIniDir.

Below is an example of Open file dialog:

static const char *gOpenTypes[] = { "ROOT files", "*.root", "All files", "*", 0, 0 }; … static TString dir("."); TGFileInfo fi; fi.fFileTypes = gOpenTypes; fi.fIniDir = StrDup(dir); new TGFileDialog(fClient->GetDefaultRoot(), this, kFDOpen,&fi); If you do not need GUI – having a look into the code of TGFileDialog and related classes might help you to achieve your goals.

Cheers, Ilka