View mode: basic / threaded / horizontal-split · Log in · Help
July 09, 2005
std.path.getDirName is not working correct?
Greetings!

say,

char[] path = "c:\\logs\\somedir";
writef(std.path.getDirName(path));

will return "c:\logs" which is not correct.  It should return "c:\logs\somedir"
since somedir is the last directory.  If it was std.path.getParentDir, then I
would agree with the outcome.  However, getDirName should return the last
directory of the path.

Am I correct?  (Please be adviced that I have been wrong before. ;-))

thanks,

josé
July 09, 2005
Re: std.path.getDirName is not working correct?
"jicman" <jicman_member@pathlink.com> wrote in message 
news:daou9m$2laq$1@digitaldaemon.com...
> char[] path = "c:\\logs\\somedir";
> writef(std.path.getDirName(path));

try

char[] path="c:\\logs\\somedir\\";

I think it's thinking that "somedir" is a filename without an extension 
(since that's entirely possible).

Also, just as a sidenote, to make it easier to write path strings, try 
WYSIWYG strings:

char[] path=`c:\logs\somedir\`;

;)
July 09, 2005
Re: std.path.getDirName is not working correct?
Jarrett Billingsley says...
>
>"jicman" <jicman_member@pathlink.com> wrote in message 
>news:daou9m$2laq$1@digitaldaemon.com...
>> char[] path = "c:\\logs\\somedir";
>> writef(std.path.getDirName(path));
>
>try
>
>char[] path="c:\\logs\\somedir\\";
>
>I think it's thinking that "somedir" is a filename without an extension 
>(since that's entirely possible).

Yeah, this works, however, this will be an input from the user.  I guess that's
another check that I'll have to make.  I would have thought that the function
would check to whether the last item was a file or not.

>
>Also, just as a sidenote, to make it easier to write path strings, try 
>WYSIWYG strings:
>
>char[] path=`c:\logs\somedir\`;

:-)  Yes, I use this also.   or

char[] path = r"c:\logs\somedir";

:-)

thanks,

jic
July 09, 2005
Re: std.path.getDirName is not working correct?
"jicman" <jicman_member@pathlink.com> wrote in message 
news:dap30j$2pjc$1@digitaldaemon.com...
> Yeah, this works, however, this will be an input from the user.  I guess 
> that's
> another check that I'll have to make.  I would have thought that the 
> function
> would check to whether the last item was a file or not.

You could check it.  Just see if the last character is a '\\' or a '/', and 
if not, append one.
July 09, 2005
Re: std.path.getDirName is not working correct?
"jicman" <jicman_member@pathlink.com> wrote in message
news:dap30j$2pjc$1@digitaldaemon.com...
> Yeah, this works, however, this will be an input from the user.  I guess
that's
> another check that I'll have to make.  I would have thought that the
function
> would check to whether the last item was a file or not.

It doesn't. It only looks at the form of the string. To test what the things
are, that is what the functions in std.file are for.
July 10, 2005
Re: std.path.getDirName is not working correct?
I think std.path.getDirName() should check whether the input string is 
directory or not. If not append "\" or "/", then get the dir name.

std.file.isdir() can do a check easily.


"Walter" <newshound@digitalmars.com> дÈëÏûÏ¢ÐÂÎÅ:dapntc$aj4$2@digitaldaemon.com...
>
> "jicman" <jicman_member@pathlink.com> wrote in message
> news:dap30j$2pjc$1@digitaldaemon.com...
>> Yeah, this works, however, this will be an input from the user.  I guess
> that's
>> another check that I'll have to make.  I would have thought that the
> function
>> would check to whether the last item was a file or not.
>
> It doesn't. It only looks at the form of the string. To test what the 
> things
> are, that is what the functions in std.file are for.
>
>
July 18, 2005
Re: std.path.getDirName is not working correct?
Shawn Liu wrote:
> I think std.path.getDirName() should check whether the input string is 
> directory or not. If not append "\" or "/", then get the dir name.
> 
> std.file.isdir() can do a check easily.
<snip top of upside-down reply>

That's because inspecting the local file system is part of the scope of 
std.file.  OTOH, the scope of std.path is to be a collection of string 
manipulation functions.  As such, they don't care about the contents of 
the local file system, nor whether the pathnames involved even relate to 
the machine you're running on.

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:- a->--- UB@ P+ L E@ W++@ N+++ o K- w++@ O? M V? PS- PE- Y? 
PGP- t- 5? X? R b DI? D G e++>++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on 
the 'group where everyone may benefit.
July 19, 2005
Re: std.path.getDirName is not working correct?
Stewart Gordon says...
>
>Shawn Liu wrote:
>> I think std.path.getDirName() should check whether the input string is 
>> directory or not. If not append "\" or "/", then get the dir name.
>> 
>> std.file.isdir() can do a check easily.
><snip top of upside-down reply>
>
>That's because inspecting the local file system is part of the scope of 
>std.file.  OTOH, the scope of std.path is to be a collection of string 
>manipulation functions.  As such, they don't care about the contents of 
>the local file system, nor whether the pathnames involved even relate to 
>the machine you're running on.

Yeah, that's all fine and dandy, however, the function should work properly, or
should be named properly or explained properly (too many uses of properly in
this sentence is not proper), or not even be written up.  If it is string
manupulationg functions, it should be in the string functions and explained that
these functions are just simulations of what a path libraries should do and do
no checking.  Nonetheless, if they are made for handling paths, then, every
possible properly built path should be taken into consideration.  Otherwise, why
make the library if they are only going to work half-way?  I love libraries,
but, they must work fully, otherwise they should not be out there.

I am sorry that I am being such a pain with this, but I have spend too many
hours trying to go through my code, thinking that it was my logic, when after
figuring it out, it was the defective library functions.  I still love D and I
am sticking with it.  I just don't like it when people defend anything without
reasoning.  I guess I am going to have to write my own libraries for handling
paths.

thanks,

josé
July 19, 2005
Re: std.path.getDirName is not working correct?
"jicman" <jicman_member@pathlink.com> wrote in message 
news:dbjkel$jsq$1@digitaldaemon.com...
> Stewart Gordon says...
>>
>>Shawn Liu wrote:
>>> I think std.path.getDirName() should check whether the input string is
>>> directory or not. If not append "\" or "/", then get the dir name.
>>>
>>> std.file.isdir() can do a check easily.
>><snip top of upside-down reply>
>>
>>That's because inspecting the local file system is part of the scope of
>>std.file.  OTOH, the scope of std.path is to be a collection of string
>>manipulation functions.  As such, they don't care about the contents of
>>the local file system, nor whether the pathnames involved even relate to
>>the machine you're running on.
>
> Yeah, that's all fine and dandy, however, the function should work 
> properly, or
> should be named properly or explained properly (too many uses of properly 
> in
> this sentence is not proper), or not even be written up.  If it is string
> manupulationg functions, it should be in the string functions and 
> explained that
> these functions are just simulations of what a path libraries should do 
> and do
> no checking.  Nonetheless, if they are made for handling paths, then, 
> every
> possible properly built path should be taken into consideration. 
> Otherwise, why
> make the library if they are only going to work half-way?  I love 
> libraries,
> but, they must work fully, otherwise they should not be out there.
>
> I am sorry that I am being such a pain with this, but I have spend too 
> many
> hours trying to go through my code, thinking that it was my logic, when 
> after
> figuring it out, it was the defective library functions.  I still love D 
> and I
> am sticking with it.  I just don't like it when people defend anything 
> without
> reasoning.  I guess I am going to have to write my own libraries for 
> handling
> paths.
>
> thanks,
>
> josé

The current phobos behavior matches what I would expect from my Perl 
(fileparse) and MATLAB (fileparts) experience. Is there an API that you use 
that checks for the directory existence? Probably the doc could use some 
work to make it more explicit that the path functions just parse strings.
July 20, 2005
Re: std.path.getDirName is not working correct?
In article <dbjlob$le8$1@digitaldaemon.com>, Ben Hinkle says...
>
>
>"jicman" <jicman_member@pathlink.com> wrote in message 
>news:dbjkel$jsq$1@digitaldaemon.com...
>> Stewart Gordon says...
>>>
>>>Shawn Liu wrote:
>>>> I think std.path.getDirName() should check whether the input string is
>>>> directory or not. If not append "\" or "/", then get the dir name.
>>>>
>>>> std.file.isdir() can do a check easily.
>>><snip top of upside-down reply>
>>>
>>>That's because inspecting the local file system is part of the scope of
>>>std.file.  OTOH, the scope of std.path is to be a collection of string
>>>manipulation functions.  As such, they don't care about the contents of
>>>the local file system, nor whether the pathnames involved even relate to
>>>the machine you're running on.
>>
>> Yeah, that's all fine and dandy, however, the function should work 
>> properly, or
>> should be named properly or explained properly (too many uses of properly 
>> in
>> this sentence is not proper), or not even be written up.  If it is string
>> manupulationg functions, it should be in the string functions and 
>> explained that
>> these functions are just simulations of what a path libraries should do 
>> and do
>> no checking.  Nonetheless, if they are made for handling paths, then, 
>> every
>> possible properly built path should be taken into consideration. 
>> Otherwise, why
>> make the library if they are only going to work half-way?  I love 
>> libraries,
>> but, they must work fully, otherwise they should not be out there.
>>
>> I am sorry that I am being such a pain with this, but I have spend too 
>> many
>> hours trying to go through my code, thinking that it was my logic, when 
>> after
>> figuring it out, it was the defective library functions.  I still love D 
>> and I
>> am sticking with it.  I just don't like it when people defend anything 
>> without
>> reasoning.  I guess I am going to have to write my own libraries for 
>> handling
>> paths.
>>
>> thanks,
>>
>> josé
>
>The current phobos behavior matches what I would expect from my Perl 
>(fileparse) and MATLAB (fileparts) experience.

I will test this out with perl and python.  I just don't have the time, right
now.

> Is there an API that you use that checks for the directory existence?
JScript.  It works as it's suppose to.


>Probably the doc could use some 
>work to make it more explicit that the path functions just parse strings. 

I wish I had the time, I would help with it.  I just don't have it.

thanks,

josé
Top | Discussion index | About this forum | D home