wxFileName AppendDir and PrependDir are the same ?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Rocketmagnet
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Aug 09, 2006 11:14 pm
Location: London
Contact:

wxFileName AppendDir and PrependDir are the same ?

Post by Rocketmagnet » Thu Feb 15, 2018 10:26 am

Hi,

I am surprised to find that wxFileName::AppendDir() and wxFileName::PrependDir() seem to do the same thing. The following code:

Code: Select all

wxFileName pathApp("C:\Code");
wxFileName pathPre("C:\Code");

pathApp.AppendDir("Project");
cout << "Append =  " << pathApp.GetFullPath() << endl;

pathPre.PrependDir("Project");
cout << "Prepend = " << pathPre.GetFullPath() << endl;
... produces this output:

Code: Select all

Append =  C:Project\Code
Prepend = C:Project\Code
Is this the expected behaviour?

User avatar
doublemax
Moderator
Moderator
Posts: 15831
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxFileName AppendDir and PrependDir are the same ?

Post by doublemax » Thu Feb 15, 2018 11:19 am

Is this the expected behaviour?
With that code, yes. Because "C:\Code" is a filename, so there is no directory in that path and therefore prepending and appending does the same.

If however c:\\Code\\ is a directory, you should write it this way:

Code: Select all

wxFileName pathApp("C:\\Code\\");
wxFileName pathPre("C:\\Code\\");
... and then you get the result you probably expect.
Use the source, Luke!

Rocketmagnet
Experienced Solver
Experienced Solver
Posts: 79
Joined: Wed Aug 09, 2006 11:14 pm
Location: London
Contact:

Re: wxFileName AppendDir and PrependDir are the same ?

Post by Rocketmagnet » Thu Feb 15, 2018 1:35 pm

Aah! Thanks.

Just digging into the code for wxGenericDirCtrl, and it doesn't seem to be consistent with adding its \ to the end of the paths. Sorted now.

Hugo

Post Reply