Hello. I am trying to create a directory with the function SHCreateDerectoryExA (); regarding the directory of the application being launched: so far unsuccessfully. Thus, all thought and thought, what is the problem.

string str_log_dir ( "..\\user\\log\\" ); SHCreateDerectoryExA ( NULL, str_log_gir.c_str(), NULL ); 

ShlObj.h connected to the project. Yes, and there is hardly a problem in converting string to const char *. As you can see, the points do not help, even here. But when creating a single file through fstream, for example, ". \ Test_file.txt", such a chip rolls. WinAPI, as I see it does not work with this. Or I don't know something.

 fstream log_file; log_file.open( ".\\engine.log", ios::binary, ios::out ); 

The directory is not created when you start the exe-shnik, but the file - please. In any case, I hope that I clearly described my lack of knowledge in WinAPI, or how else this can be called. I ask to help, I sit for 2 hours, google, but all to no avail.

  • Why SHCreateDerectoryEx, if there is CreateDirectory? Well, the standard rule: if the function does not work - see in MSDN what is written about receiving the error code. - Vladimir Martyanov
  • Then, Vladimir, that CreateDirectory does not work with subdirectories. - valentin_bs
  • Error code show - gecube
  • You should not want to create a directory in the subdirectory relative to the application on Windows. Adult programs are in a write-protected directory, like Program Files. For your problem: check your current directory. - VladD
  • I checked the directory. Everything is in order, except that for some reason the specified directories are not created when the same program is launched. And the theme of adults prog in this case is not important: this is my test for the file system. Files, directories, extensions, etc. - valentin_bs

1 answer 1

In function notes

ERROR_BAD_PATHNAME: The pszPath parameter was set to a relative path.

So do not use the relative path ...

  • Not created. This function just has to create it, presumably. If to remove blesklesh, the compiler will give a warning: an unknown escape sequence. - valentin_bs
  • one
    Yes, the main problem is that this function does not work with relative paths . Convert programmatically relative path to absolute. Then eats everything. - Harry
  • Thanks to all. It seems to work, harder, but still. - valentin_bs