Re: looping over files

From: Marco van Leeuwen (mvl@nikhef.nl)
Date: Fri Mar 03 2000 - 15:53:45 MET


Hi,


Below you will find some code, which I copied from one of my programs.
It is not very elegant, but it works!


Good luck,

Marco van Leeuwen.


------ Example code


  Char_t dirname[]="data/new";
  void* dir=gSystem->OpenDirectory(gSystem->ExpandPathName(dirname));
  int nruns=0;
  Char_t *file_name;
  TString Tname;
  Char_t file_list[100][256];

  do {
    file_name = gSystem->GetDirEntry(dir);
      Tname=file_name;
      while (!Tname.Contains(".root") && file_name){
	file_name = gSystem->GetDirEntry(dir);
	Tname=file_name;
	//printf("%s\n",Tname.Data());
      }

      if (file_name && Tname.Contains("98h")) {
	sprintf(&file_list[nruns],"%s/%s",dirname,file_name);
	printf("file %d: %s\n",nruns,file_list[nruns]);
	nruns++;
      }
      
  } while (file_name);


Jens Ivar Jordre wrote:
> 
> Hello rooters of the world.
> 
> I'm working on a macro to analyze several data files all being in the same
> directory. Btw. I'm using v2.23/12 on RH6.1. Now, I want to go through the
> files one by one. Therefore I wonder if there is a way in ROOT to be
> able to get hold of the names of files in a directory in succesive
> order.
> I tried both with both TSystem's (i.e. gSystem) and TUnixSystem's
> GetDirEntry(void *dirp), but now luck. What kind of pointers are allowed
> for 'dirp' in this function call?
> The description of TUnixSystem::GetDirEntry(..) is the best interpretation
> of what I want to do:
> ---
> const char* GetDirEntry(void *dirp)
> 
>  Get next Unix file system directory entry. Returns 0 if no more entries.
> ---
> So, any help from around the world?
> 
> --------------------------------------------------------------
> Jens Ivar Jřrdre, masterstud. in Experimental Nuclear Physics
> Addr.: Dep. of Phys., UiB, Allégt. 55, N-5007 BERGEN, NORWAY
> E-mail: JensIvar.Jordre@fi.uib.no, Phone office: (+47)55582734
> Web: http://www.fi.uib.no/~jens
> 
> "Time's fun when you're having flies."
> -- Kermit the Frog



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:20 MET