Re: TFile-.* behaviour (long)

Rene Brun (Rene.Brun@cern.ch)
Wed, 01 Apr 1998 10:59:58 +0200


Mariusz Stanczak wrote:
>
> I get rather strange results under WinNT:
>
> the current keyboard layout is 437
> *******************************************
> * *
> * W E L C O M E to R O O T *
> * *
> * Version 2.00/03 28 March 1998 *
>
> TFile->pwd always returns "/" as the current directory:
>
> root [2] TFile test("test.root")
> root [3] test.ls()
> TFile** test.root
> TFile* test.root
> root [4] test.mkdir("dir1l1")
> (class TDirectory*)0xa0e118
> root [5] test.ls()
> TFile** test.root
> TFile* test.root
> TDirectory* dir1l1 dir1l1
> root [6] test.pwd()
> test.root:/
> root [7] test.cd("dir1l1")
> root [8] test.pwd()
> test.root:/
>

This is the correct behaviour. The statement test.pwd() prints
the name of the directory pointed by test.
What you can do is teh following:
test.cd("dir1l1");
gDirectory->pwd(); //the global gDirectory points to the current dir
TDirectory *dir1l1 = gDirectory;
dir1l1->pwd(); //same as above

> New files are created in the right directory, but how is one to keep track
> where in the directory tree one is at a given moment?
>
> root [18] test.mkdir("dir1l2")
> (class TDirectory*)0xa0e998
> root [19] test.ls()
> TFile** test.root
> TFile* test.root
> TDirectory* dir1l1 dir1l1
> TDirectory* dir1l2 dir1l2
>
> Further, it is possible to create "invalid" directory names... in the
> following
> if ROOT is to mimic the directory behaviour of an OS file system the
> command;
>
> root [21] test.mkdir("dir2l2/dir1l3")
>
> would be expected to create directory "dir2l2" and "under" it a subdirectory
> "dir1l3" but the result is;
>
> (class TDirectory*)0xa0fa18
> root [22] test.ls()
> TFile** test.root
> TFile* test.root
> TDirectory* dir1l1 dir1l1
> TDirectory* dir1l2 dir1l2
> TDirectory* dir2l2/dir1l3 dir2l2/dir1l3
>
> and since the "/" is a directory seperator, all other operations fail unless
> the "/" is escaped:
>
> root [23] test.cd("dir2l2/dir1l3")
> Error in <TFile::cd>: Unknown directory dir2l2
> root [24] test.Delete("dir2l2\/dir1l3")

Root version 2.00/03 cannot create both dir2l2 and dir1l3 in the
same call. You need :
test.cd();
test.mkdir("dir2l2");
test.cd("dir2l2");
TDirectory *dir2l2 = gDirectory;
dir2l2->mkdir("dir1l3"); //etc..

I have protected mkdir against slashes in my current version.

In Root version 2.00/03, there is no way to delete one single directory.
I have implemented this possibility in my current version (2.00/04).

Rene Brun