views:

678

answers:

2

Hello all,

Not sure if this is intended behavior or a bug or a wrong function that I'm using, but the problem is that PathCombine() returns a wrong path on a Vista box.

The relative path is (as exported by the WMP to a playlist):

..\..\..\Public\Music\Sample Music\Amanda.wma

The path it's relative to is:

C:\Users\userX\Music\Playlists\playlist.wpl

and PathCombine() returns:

C:\Users\userX\Public\Music\Sample Music\Amanda.wma

however, the file is actually located here (judging by the Explorer and the fact that I can't open it from the code):

C:\Users\Public\Music\Sample Music\Amanda.wma

Is this a known issue? Is there some other function I should be using?

Thanks in advance.

+2  A: 

The documentation for PathCombine specifies that the second parameter, lpszDir, is "A pointer to a null-terminated string of maximum length MAX_PATH that contains the directory path." You appear to be passing the fully qualified name of a file inside the directory, instead of the fully qualified name of the directory. So, it removes three components: playlist.wpl, Playlists, and Music, and then appends the remainder.

You should be able to use PathRemoveFileSpec to remove the file part from your directory path.

cunkel
Hmm, I'll try that - thanks.
dennisV
Yep, that works now - thanks.
dennisV
+1  A: 

When you combine your two strings, you get the following.

C:\Users\userX\Music\Playlists\playlist.wpl\..\..\..\Public\Music\Sample Music\Amanda.wma

Since each ".." will wipe out the preceding section, you end u[p with the following sequence:

C:\Users\userX\Music\Playlists\playlist.wpl\..\..\..\Public\Music\Sample Music\Amanda.wma
C:\Users\userX\Music\Playlists\..\..\Public\Music\Sample Music\Amanda.wma
C:\Users\userX\Music\..\Public\Music\Sample Music\Amanda.wma
C:\Users\userX\Public\Music\Sample Music\Amanda.wma

That's because "PathCombine()" is not bothered by whether any segments of your path are files or directories. It's just a relatively dumb way of matching special navigation characters (".." and ".") against real navigation segments to form a path without those special navigation characters.

It's just assuming that "playlist.wpl" is a directory name in your case. Strip that off (or add another ".." at the start of your relative path, a trick to avoid extraneous code for stripping of the filename section) and it should work okay.

paxdiablo