How can read files in a directory

Hi,
I am a new user; how can read ascii files in a directory? I’m trying to update the code found in this forum :

void list_files(const char *dirname="mypath", const char *ext=".txt") {
  TSystemDirectory dir(dirname, dirname);
  TList *files = dir.GetListOfFiles();
  if (files) {
    TSystemFile *file;
    TString fname;
    TIter next(files);
    while ((file=(TSystemFile*)next())) {
      fname = file->GetName();
      if (!file->IsDirectory() && fname.EndsWith(ext)) {
	FILE *fin = fopen(fname.Data(),"rt");
	cout << fname.Data() << endl;
      }
    }
  }
}

I’m grateful for any help!!!

You can use any standard C / C++ function / method.

Thanks; I already tried several options without success.
void list_files(const char *dirname=“mypath”, const char *ext=".txt") {
TSystemDirectory dir(dirname, dirname);
TList *files = dir.GetListOfFiles();
if (files) {
TSystemFile file;
TString fname;
TIter next(files);
while ((file=(TSystemFile
)next())) {
fname = file->GetName();
if (!file->IsDirectory() && fname.EndsWith(ext)) {
FILE *fin = fopen(fname.Data(),“rt”);
fclose(fin); //just to check

cout << fname.Data() << endl;
  }
}

}
}

but I have this error : fopen parameter mismatch param[0].

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.