# Problem with TSystem::DirName() on WinXP

**URL:** <https://root-forum.cern.ch/t/problem-with-tsystem-dirname-on-winxp/6416>\
**Category:** ROOT\
**Created:** [April 19, 2008, 12:49pm UTC](https://root-forum.cern.ch/t/problem-with-tsystem-dirname-on-winxp/6416 "2008-04-19T12:49:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstrato](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@cstrato](https://root-forum.cern.ch/u/cstrato)\
**Post date:** [April 19, 2008, 12:49pm UTC](https://root-forum.cern.ch/t/problem-with-tsystem-dirname-on-winxp/6416/1 "2008-04-19T12:49:34Z")

</div>

Dear ROOTers

I have just realized that on WinXP the directory to be returned is incomplete.

When I do:

```auto
name = "C:/path/to/file"
dirname = gSystem->DirName(name);
```

The returned dirname is: "/path/to"  
This works on WinXP, too.

However, when I use an external drive and do:

```auto
name = "E:/path/to/file"
dirname = gSystem->DirName(name);
```

The returned dirname is also: "/path/to"  
As a result I get the error message:  
SysError in TFile::TFile: file /path/to cannot be opened

Is this a known problem?  
Is there a workaround?

P.S.: I am using root 5.18/00.

Best regards  
Christian

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [April 19, 2008, 4:02pm UTC](https://root-forum.cern.ch/t/problem-with-tsystem-dirname-on-winxp/6416/2 "2008-04-19T16:02:29Z")

</div>

Hi Christian,  
Just try: `gSystem->ExpandPathName(name);`  
Cheers,  
Bertrand.

---

<div class="post-metadata">

**Author:** ![cstrato](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/c/bbe5ce/32.png) [@cstrato](https://root-forum.cern.ch/u/cstrato)\
**Post date:** [April 19, 2008, 6:35pm UTC](https://root-forum.cern.ch/t/problem-with-tsystem-dirname-on-winxp/6416/3 "2008-04-19T18:35:38Z")

</div>

Dear Bertrand

Thank you, I use ExpandPathName() later in my method, but for preprocessing I need a different solution.  
I am now using my own function Name2Path(), which solves my problem.

Nevertheless, after some testing things are getting really strange:  
When copying the source code to the attached macro “test.C” and testing the macro in rootcint it seems that  
the source code is ok, however:

This is the output on my Mac:

```auto
root [0] gSystem->BaseName("E:/Volumes/GigaDrive/CRAN/Workspaces/Exon/temp")
(const char* 0x24f6b96)"temp"
root [1] gSystem->DirName("E:/Volumes/GigaDrive/CRAN/Workspaces/Exon/temp") 
(const char* 0x228b4b0)"E:/Volumes/GigaDrive/CRAN/Workspaces/Exon"

root [2] .L test.C                                                          
root [3] DirName("E:/Volumes/GigaDrive/CRAN/Workspaces/Exon/temp")          
(const char* 0x260fac0)"E:/Volumes/GigaDrive/CRAN/Workspaces/Exon"
```

Everything is ok!

But this is the output on WinXP:

```auto
root [0] gSystem->BaseName("E:/CRAN/Workspaces/Exon/temp/tmp_310151.root")
(const char* 0x128b8b5)"tmp_310151.root"
root [1] gSystem->DirName("E:/CRAN/Workspaces/Exon/temp/tmp_310151.root")
(const char* 0x12a1260)"/CRAN/Workspaces/Exon/temp"

root [2] .L test.C
root [3] DirName("E:/CRAN/Workspaces/Exon/temp/tmp_310151.root")
(const char* 0x128b7f0)"E:/CRAN/Workspaces/Exon/temp"
```

As you see, the function DirName() from test.C gives the correct result, while gSystem-\>DirName() gives the wrong result!!

Although I do not understand this behavior, I think that DirName() should be corrected to handle WinXP correctly.

Best regards  
Christian  
[test.C](https://root-forum.cern.ch/uploads/default/original/2X/8/81ec72d24820e760950ccbd8ba3585a504495311.C) (977 Bytes)
