 |
|
 |
static std::wstring m_buffer;
in the .h file makes this class non-thread safe. Totally un-necessary.
replace
m_buffer = L"";
with
std::wstring buffer(L"");
(and rename usages)
|
|
|
|
 |
|
|
 |
|
 |
Have a look at boost.filesystem. It is implemented in a portable way.
|
|
|
|
 |
|
 |
Hi,
boost.filesystem seems to be an interesting alternative.
I just skimed over the boost.filesystem's homepage so I didn't gather the entire functional range yet.
But I found out two things: it's free, and renaming file is supported (I am currently working on a renaming tool).
The main functionality of this tool is put in a library too, so I guess it would be a good idea to base my own code on a portable library like this.
I think I'll have a try.
Thanks for your references
Achim Klein
p.s.
For those who are interested: boost.filesystem
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
 |
|
 |
Paste this URL into VS2003:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2005JAN.1033/shellcc/platform/shell/reference/shlwapi/path/path.htm
Shell Path Handling Functions
--------------------------------------------------------------------------------
This section describes the Microsoft Windows Shell path handling functions. The programming elements explained in this documentation are exported by Shlwapi.dll and defined in Shlwapi.h and Shlwapi.lib.
PathAddBackslash
Adds a backslash to the end of a string to create the correct syntax for a path. If the source path already has a trailing backslash, no backslash will be added.
PathAddExtension
Adds a file extension to a path string.
PathAppend
Appends one path to the end of another.
PathBuildRoot
Creates a root path from a given drive number.
PathCanonicalize
Canonicalizes a path.
PathCombine
Concatenates two strings that represent properly formed paths into one path, as well as any relative path pieces.
PathCommonPrefix
Compares two paths to determine if they share a common prefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".
PathCompactPath
Truncates a file path to fit within a given pixel width by replacing path components with ellipses.
PathCompactPathEx
Truncates a path to fit within a certain number of characters by replacing path components with ellipses.
PathCreateFromUrl
Takes a file URL and converts it to a Microsoft MS-DOS path.
PathFileExists
Determines whether a path to a file system object such as a file or directory is valid.
PathFindExtension
Searches a path for an extension.
PathFindFileName
Searches a path for a file name.
PathFindNextComponent
Parses a path for the next path component.
PathFindOnPath
Searches for a file.
PathFindSuffixArray
Determines if a given file name has one of a list of suffixes.
PathGetArgs
Finds the command line arguments within a given path.
PathGetCharType
Determines the type of character with respect to a path.
PathGetDriveNumber
Searches a path for a drive letter within the range of 'A' to 'Z' and returns the corresponding drive number.
PathIsContentType
Determines if a file's registered content type matches the specified content type. This function obtains the content type for the specified file type and compares that string with the pszContentType. The comparison is not case sensitive.
PathIsDirectory
Verifies that a path is a valid directory.
PathIsDirectoryEmpty
Determines whether or not a specified path is an empty directory.
PathIsFileSpec
Searches a path for any path delimiting characters (for example, ':' or '\' ). If there are no path delimiting characters present, the path is considered to be a File Spec path.
PathIsHTMLFile
Determines if a file is an HTML file. The determination is made based on the content type that is registered for the file's extension.
PathIsLFNFileSpec
Determines whether or not a file name is in long format.
PathIsNetworkPath
Determines whether a path string represents a network resource.
PathIsPrefix
Searches a path to determine if it contains a valid prefix of the type passed by pszPrefix. A prefix is one of these types: "C:\\", ".", "..", "..\\".
PathIsRelative
Searches a path and determines if it is relative.
PathIsRoot
Parses a path to determine if it is a directory root.
PathIsSameRoot
Compares two paths to determine if they have a common root component.
PathIsSystemFolder
Determines if an existing folder contains the attributes that make it a system folder. Alternately indicates if certain attributes qualify a folder to be a system folder.
PathIsUNC
Determines if the string is a valid Universal Naming Convention (UNC) for a server and share path.
PathIsUNCServer
Determines if a string is a valid UNC for a server path only.
PathIsUNCServerShare
Determines if a string is a valid UNC share path, \\ server\ share.
PathIsURL
Tests a given string to determine if it conforms to a valid URL format.
PathMakePretty
Converts a path to all lowercase characters to give the path a consistent appearance.
PathMakeSystemFolder
Gives an existing folder the proper attributes to become a system folder.
PathMatchSpec
Searches a string using a MS-DOS wild card match type.
PathParseIconLocation
Parses a file location string containing a file location and icon index, and returns separate values.
PathQuoteSpaces
Searches a path for spaces. If spaces are found, the entire path is enclosed in quotation marks.
PathRelativePathTo
Creates a relative path from one file or folder to another.
PathRemoveArgs
Removes any arguments from a given path.
PathRemoveBackslash
Removes the trailing backslash from a given path.
PathRemoveBlanks
Removes all leading and trailing spaces from a string.
PathRemoveExtension
Removes the file extension from a path, if there is one.
PathRemoveFileSpec
Removes the trailing file name and backslash from a path, if it has them.
PathRenameExtension
Replaces the extension of a file name with a new extension. If the file name does not contain an extension, the extension will be attached to the end of the string.
PathSearchAndQualify
Determines if a given path is correctly formatted and fully qualified.
PathSetDlgItemPath
Sets the text of a child control in a window or dialog box, using PathCompactPath to make sure the path fits in the control.
PathSkipRoot
Parses a path, ignoring the drive letter or UNC server/share path parts.
PathStripPath
Removes the path portion of a fully qualified path and file.
PathStripToRoot
Removes all parts of the path except for the root information.
PathUndecorate
Removes the decoration from a path string.
PathUnExpandEnvStrings
Takes a fully qualified path, and replaces several folder names with their associated environment string.
PathUnmakeSystemFolder
Removes the attributes from a folder that make it a system folder. This folder must actually exist in the file system.
PathUnquoteSpaces
Removes quotes from the beginning and end of a path.
SHSkipJunction
Checks a bind context to see if it is safe to bind to a particular component object.
UrlApplyScheme
Takes a URL string, determines a scheme for it, and returns a string with an appropriate prefix.
UrlCanonicalize
Takes a URL string and converts it into canonical form.
UrlCombine
When provided with a relative URL and its base, returns a URL in canonical form.
UrlCompare
Makes a case-sensitive comparison of two URL strings.
UrlCreateFromPath
Takes a MS-DOS path and converts it to a canonicalized URL.
UrlEscape
Converts characters in a URL that might be altered during transport across the Internet ("unsafe" characters) into their corresponding escape sequences.
UrlEscapeSpaces
A macro that converts space characters into their corresponding escape sequence.
UrlGetLocation
Retrieves the location from a URL.
UrlGetPart
Accepts a URL string and returns a specified part of that URL.
UrlHash
Hashes a URL string.
UrlIs
Tests whether or not a URL is a specified type.
UrlIsFileUrl
Tests a URL to determine if it is a file URL.
UrlIsNoHistory
Returns whether or not a URL is a No History URL.
UrlIsOpaque
Returns whether a URL is opaque.
UrlUnescape
Converts escape sequences back into ordinary characters.
UrlUnescapeInPlace
Converts escape sequences back into ordinary characters and overwrites the original string.
|
|
|
|
 |
|
 |
Wow. Quite a lot path handling routines.
And I didn't even know one of them.
Thanks for this information.
Now that I know them, I consider to use some of them in my MFC projects, but I guess PathInfo will not be put on the scrap heap in the near future. Because actually I'm developing a lot of console based tools without using any Microsoft specific code.
But thanks a lot for this long list.
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
 |
|
 |
I'm not super keen on shell path (Shlwapi.h)
I think your PathInfo.h is very clean and useful.
However, you might want to consider using the same API as System.IO.Path in .NET framework
ChangeExtension - Changes the extension of a path string.
Combine - Combines two path strings.
GetDirectoryName - Returns the directory information for the specified path string.
GetExtension - Returns the extension of the specified path string.
GetFileName - Returns the file name and extension of the specified path string.
GetFileNameWithoutExtension - Returns the file name of the specified path string without the extension.
GetFullPath - Returns the absolute path for the specified path string.
GetPathRoot - Gets the root directory information of the specified path.
GetTempFileName - Returns a uniquely named zero-byte temporary file on disk and returns the full path to that file.
GetTempPath - Returns the path of the current system's temporary folder.
HasExtension - Determines whether a path includes a file name extension.
IsPathRooted - Gets a value indicating whether the specified path string contains absolute or relative path information.
|
|
|
|
 |
|
 |
Version 1.1 has been submitted.
I hope it will be edited within the next week.
Regards
Achim Klein
If I have seen further, it is by standing on the shoulders of giants.
Isaac Newton
|
|
|
|
 |
|
 |
When given a path like "C:\SomePath\SomeDirA\..\SomeDirB\foo.txt" could you remove the unneeded "SomeDirA\..\" from the path? In your test app, CFileDialog prevents this from being entered, but if your app used an edit box for the path, or accepted a path via the command line, then this scenario could happen. Low priority, but a welcome feature.
|
|
|
|
 |
|
 |
If using Windows, try
PathCanonicalize
This is a "Shlwapi.h" function, part of Path Functions under Shell Utility APIs part of Internet Tools & Technologies.
This doesn't meet the constraints of this article, I understand, which was to develop generalize - non microsoft specific - path code.
|
|
|
|
 |
|
 |
Does it handle UNC-notation, too ("\\myserver\myshare\somefolder\somefile.ext")?
--
Affordable Windows-based CMS for only 99 €: try www.zeta-producer.com for free!
|
|
|
|
 |
|
 |
http://www.codeproject.com/string/CPathSplit.asp
Kochise
In Code we trust !
|
|
|
|
 |
|
|
 |
|
 |
Yup, right I tried to make mine for heavy duty purposes, trying to cover all path format. I have here and unrelease version which feature wildcard matching and automatic search/replace... So handy I use it everywhere in my productions !
Kochise
In Code we trust !
|
|
|
|
 |
|
 |
Every project I start, is normally copying the functions which perform these actions.
This is very interesting, making a special class for them!
Geert
Want to spread the newest version of your software automatically for free? Use Updater!
Visit my website: www.gvhsoftware.org
|
|
|
|
 |