Directory names in ROOT

Can someone explain me please why the following root script fails:
root [0] gDirectory -> mkdir( “OH:TEST” );
root [1] gDirectory -> cd( “OH:TEST” );
Error in TROOT::cd: No such file OH:TEST

I have also several related questions:

  1. Is it bug or feature?
  2. Can I still cd to the directories which contain “:” character?
  3. Where can I find the list of charactes which can not be used in the root dir/file names?

Many thanks

When using ‘:’, the left part is assume to be a filename to be opened (see TDirectory::cd documentation).

Philippe

[quote=“pcanal”]When using ‘:’, the left part is assume to be a filename to be opened (see TDirectory::cd documentation).

Philippe[/quote]

Thank you for the hint. But questions 2 and 3 are still valid.

[quote]2. Can I still cd to the directories which contain “:” character? [/quote]SomewhatTDirectory *dir = (TDirectory*)gDirectory->FindObject(name); if (dir) dir->cd();

[quote]3. Where can I find the list of charactes which can not be used in the root dir/file names? [/quote]I don’t think that we have a master list … especially since whether a character is legal or not depend a bit of the application.

Cheers,
Philippe

Hello, Philippe!

Seems, like this solution does not work for me.
I attached the simple root file with “:” in the name of TDirectory.
I’ve tried to go inside this TDirectory by this code:

#include <iostream> 
#include <TFile.h> 
#include <TKey.h> 
#include <TROOT.h>

int main() {
    using namespace std;
    TFile *f_input = new TFile("Tdir.root");

    TIter next(f_input->GetListOfKeys());
    TKey *key;

     while ((key= (TKey*)next())) {
        cout<<"I'm in this dir: "<<gDirectory->GetName()<<endl;
        cout<<"Trying to go to : "<<key->GetName()<<endl;
        
        TDirectory* subdir = (TDirectory*)gDirectory->FindObject(key->GetName());
        if (subdir) subdir->cd();
        
        cout<<"Now I'm in this dir: "<<gDirectory->GetName()<<endl; 
    }
    f_input->Close();
    return 1;
}

The result is:

I'm in this dir: Tdir.root
Trying to go to : Top::folder
Now I'm in this dir: Tdir.root

Am I doing something wrong?
Best regards, Iurii

Tdir.root (1.3 KB)