0

I have a directory, contains files:

"bc[1]",
"bc[2]",
.
.
.
"abc[1]",
"abc[2]",
.
.
.

and some other files.

I would like to find files with name "bc", but not include "abc" files.. I have the following code, it listed all the "bc" and "abc" files.

f->cd("SomePath");
  TIter next(gDirectory->GetListOfKeys());
  TKey *key;
  while ((key = (TKey*)next()) ){
                if (key != nullptr){
                  string name = key->GetName();
                  if (name.find("bc")!= std::string::npos){
                    cout<<name<< endl;
                  }
                }
              }

Thanks in advance for your help!

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
Arwen
  • 1
  • 1
    `if (name.find("bc")==0)` - or did I miss the point. – WhozCraig Mar 03 '21 at 10:16
  • What is `TIter` and `TKey` Please make a [mre]. Perhaps you want [`std::string::starts_with`](https://en.cppreference.com/w/cpp/string/basic_string/starts_with)? – Ted Lyngmo Mar 03 '21 at 10:18

0 Answers0