Discussion:
SHCreateDirectory fails when pszPath = root drive
(too old to reply)
Tina
2006-02-28 19:49:29 UTC
Permalink
I create files based on SHCreateDirectory results, but when the pszPath
happens to be the root drive, the function fails (i.e. pszPath
parameter = "C:\" will fail but pszPath parameter = "C:\Files\Images"
will not). Is there a reason for this? Should I simply used a different
function if pszPath happens to be a root drive? Advice needed. Thanks.
Kellie Fitton
2006-02-28 19:57:31 UTC
Permalink
Hi,

What is the returned error code when the function fails ?

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shcreatedirectory.asp

Kellie.
Tina
2006-02-28 20:00:20 UTC
Permalink
It dosen't return any of those error codes listed in the documentation.
It returns an integer '5' which turns out to be:

//
// MessageId: ERROR_ACCESS_DENIED
//
// MessageText:
//
// Access is denied.
//
#define ERROR_ACCESS_DENIED 5L

in the winerror.h file. There are no special permissions on my C drive.
Kellie Fitton
2006-02-28 20:06:33 UTC
Permalink
Hi,

Do you get the same error when using the following API:

SHCreateDirectoryEx()

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shcreatedirectoryex.asp

Kellie.
Tina
2006-02-28 20:13:52 UTC
Permalink
Same error code returned when using SHCreateDirectoryEx(. . .).
Kellie Fitton
2006-02-28 20:22:45 UTC
Permalink
Hi,

Ok, how about the following function:

CreateDirectory()

Then,

GetLastError()
FormatMessage()

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createdirectory.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/getlasterror.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/formatmessage.asp

Kellie.
Tina
2006-02-28 20:31:55 UTC
Permalink
Same error code once again.
Kellie Fitton
2006-02-28 20:57:45 UTC
Permalink
Hi,

What security context does the process have ?

Is that a service process you are running ?

What is the operating system ?

Kellie.
[jongware]
2006-02-28 20:53:50 UTC
Permalink
Post by Tina
I create files based on SHCreateDirectory results, but when the pszPath
happens to be the root drive, the function fails (i.e. pszPath
parameter = "C:\" will fail but pszPath parameter = "C:\Files\Images"
will not). Is there a reason for this? Should I simply used a different
function if pszPath happens to be a root drive? Advice needed. Thanks.
This function creates a file system folder whose fully-qualified path is
given by pszPath. (MSDN)
The main reason seems to be that you don't specifiy something to be created.
Also, logically you *can't* create a root dir since there wouldn't be
anything to create it *in*.
If pszPath is the directory you want to create, first test if there is
anything to create. For a root dir, either pszPath is empty or it consists
of only a single backslash.

[Jongware]
Tina
2006-02-28 21:07:54 UTC
Permalink
I went with checking ::PathIsRoot(...) to check for this special case
(since most of my cases involve actual paths) and handling what to do
next appropriately. Thanks.

Loading...