[ROOT] Re: problem with TString's and char's

From: Rene Brun (Rene.Brun@cern.ch)
Date: Fri Nov 28 2003 - 08:59:23 MET


Hi Daniela,

You can do something like:

{
  const char *basename;
  TString completepath = "/user/daniela/mydir/";
  TList  *filelist = new TList;
  void *dirhandle = gSystem->OpenDirectory("."); //current dir
  while ((basename = gSystem->GetDirEntry(dirhandle))) {
    if (!strstr(basename, ".root")) continue;
    TString fullname = completepath + basename;
    filelist->Add(new TObjString(fullname));
  }
  filelist->ls();
}

Rene Brun

Daniela Kaefer wrote:
> 
> Hello,
> 
> I want to fill .root-files in a certain directory into a filelist. I used to do
> this with char, but now "completepath" has to be of type TString... Can anybody
> help me, please?  I do not need basename, dirhandle or fullname any further,
> just completepath. Thanks for any tipp.
> 
>   const Text_t *basename;
>   TList  *filelist = new TList;
>   while ((basename = gSystem->GetDirEntry(dirhandle))) {
>     // skip non-root files
>     //--------------------
>     if (!strstr(basename, ".root")) continue;
>     Text_t *fullname = new
> Text_t[strlen((Char_t)completepath)+strlen(basename)+2];
>     strcpy(fullname, (Char_t)completepath);
>     strcat(fullname, "/");
>     strcat(fullname, basename);
> 
>     // fill root-file names into <filelist>
>     //-------------------------------------
>     filelist->Add(new TObjString(fullname));
>     rootfiles++;
>     delete fullname;
>   }
> 
> Cheers, Daniela
> 
>  +------------------------------------------------------------+
>  | Daniela Kaefer       | email: kaefer@physik.rwth-aachen.de |
>  | III. Phys.Institut A |        kaefer@fnal.gov     \_L_/    |
>  | Physikzentrum        |                            /* *\/   |
>  | 52056 Aachen         | work: +49-(0)241-80-27243  \_*_/\   |
>  | Germany              | home: +49-(0)2472-7163     / | \    |
>  +------------------------------------------------------------+



This archive was generated by hypermail 2b29 : Thu Jan 01 2004 - 17:50:17 MET