Append slash to pathname |
![]() |
|
|
|
|
|
This is a utility method that comes very handy when an application is manipulating pathnames. What it does:
In Windows, a backward slash is used; in Linux / gcc, the forward slash is used. This handles a common difference between path specifications in the two OS-es.
The method will not verify whether the passed specification is syntactically valid, existing, etc; it just appends a slash to a non-empty string if it's not already there.
The method returns a reference to the string itself.
Example:
Str filepath = user_given_path;
filepath.EndInSlash().AddString(_T("config.xml"));
If the user_given_path string above was empty, the resulting filepath would reference a file in the current directory. If, however, a folder was specified, the separating slash would be added (if it's not there already) and a fully qualified file path constructed.
See also: Adding to Strings