Attributes TSystemFile

Hi, I am iterating over a TSystemDirectory and want to select the last modified file.

Is it possible to access unix-like attributes from a TSystemFile ?

Hi @segonzal ,

this is a question for @pcanal , let’s ping him.

Cheers,
Enrico

You can use:

   Long64_t size;
   Long_t id, flags, modtime;
   const char *dirfile = GetTitle();
   TString savDir = gSystem->WorkingDirectory();
   gSystem->ChangeDirectory(dirfile);
   gSystem->GetPathInfo(systemfile->GetName(), &id, &size, &flags, &modtime);
   gSystem->ChangeDirectory(savDir);

Hi Philippe, somehow I do not manage to make it working. This is what I’ve done (I am running in mac, root version at the end)

  1. Create test directory
mkdir adir
cd adir
  1. Create files with random content, different size
mkfile -n 1m f1
mkfile -n 2m f2
  1. Checking files
[sergio@mbp13]:~/adir$ stat -x f1
  File: "f1"
  Size: 1048576      FileType: Regular File
  Mode: (0600/-rw-------)         Uid: (  501/  sergio)  Gid: (   20/   staff)
Device: 1,14   Inode: 126639650    Links: 1
Access: Wed Aug 24 09:38:46 2022
Modify: Wed Aug 24 09:40:39 2022
Change: Wed Aug 24 09:40:39 2022
 Birth: Wed Aug 24 09:38:46 2022

[sergio@mbp13]:~/adir$ stat -x f2
  File: "f2"
  Size: 2097152      FileType: Regular File
  Mode: (0600/-rw-------)         Uid: (  501/  sergio)  Gid: (   20/   staff)
Device: 1,14   Inode: 126639651    Links: 1
Access: Wed Aug 24 09:38:47 2022
Modify: Wed Aug 24 09:40:45 2022
Change: Wed Aug 24 09:40:45 2022
 Birth: Wed Aug 24 09:38:47 2022
  1. using a macro:
void checkFiles(const char *path="adir"){
  TSystemDirectory *dir = new TSystemDirectory("",path);
  TList *files = dir->GetListOfFiles();

  TSystemFile *file;
  string sname;
  TIter next(files);
  
  while( (file=(TSystemFile*)next()) ){
    TString fname = file->GetName();
    sname = fname.Data();

    if(file->IsDirectory()) continue; // skip '.' and '..'

    Long64_t size;
    Long_t id, flags, modtime;

    TString savDir = gSystem->WorkingDirectory();
    gSystem->ChangeDirectory(sname.c_str());
    gSystem->GetPathInfo(file->GetName(), &id, &size, &flags, &modtime);

     cout << endl << "file = " << sname << endl;
    cout << " - Attributes: id=" << id << " size=" << size << " flags=" << flags << " modtime=" << modtime << endl;

    gSystem->ChangeDirectory(savDir);    

  } // end loop in files

  delete files;  
  delete dir;
}

I get the same info for both:

[sergio@mbp13]:~$ root
root [0] .x checkFiles.C 

file = f2
 - Attributes: id=5100642400 size=6159285168 flags=5099251984 modtime=5100642400

file = f1
 - Attributes: id=5100642400 size=6159285168 flags=5099251984 modtime=5100642400

ROOT Version: 6.24/00
Built for macosxarm64 on Apr 14 2021, 14:33:50
From tags/v6-24-00@v6-24-00

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