0

I am using vs 2010 in windows.
In my program, I want to create a new directory under the current directory.
I use

TCHAR szPath[MAX_PATH];  

GetModuleFileName( NULL, szPath, MAX_PATH ); 

And the string of szPath is "E:\A20J\Bin\***.exe".
But when I use:

BOOL bol = CreateDirectory("Path", NULL);

bol becomes 1, which means successful.
But under the "E:\A20J\Bin\", I found no such directory as "Path" even after refreshing, why?

Al2O3
  • 3,103
  • 4
  • 26
  • 52

1 Answers1

0

The path of the executable is not indicative of the directory in which the current process is executing. Use GetCurrentDirectory() to detemine the directory in which the process is executing, and the directory "Path" will have been created there. If you wish to create the directory in the same directory as the binary then some string manipulation is required to construct the path.


Note that CreateDirectory() returns non-zero only if it creates the directory. The directory may already exist which you may wish to not treat as a failure (see this old answer of mine Create a directory if it doesn't exist).

Community
  • 1
  • 1
hmjd
  • 120,187
  • 20
  • 207
  • 252