Create folders...

Nov 1, 2011 at 4:22pm
Hi all.

Actually I'm using this code for creating folders:

1
2
3
4
5
6
7
8
9
10
11
        char buf[MAX_PATH];
	DWORD dir = GetCurrentDirectory(MAX_PATH, buf);
	CString directory = buf;
        directory += "\\A";
	if(!CreateDirectory(directory,NULL))
		switch (GetLastError()) {
			case ERROR_ALREADY_EXISTS: //Folder exists
				break;
			default:
			;
		}

In this case
it creates A folder inside the current directory.

Now my question is:

is it possible to use any command that creates some folders instead of only one?

Example if directory = "C:\\A\\B\\C";

Is there any command that creates directly those 3 folders or i would have to create them one by one.

It doesnt work my function if i use directory = "c:\\a\\b\\c" it wont create none of the folders i would like to create.
Thanks in advance...

I hope you understand what i mean.

regards
Nov 1, 2011 at 5:56pm
For Windows 2000 and later, you could use SHCreateDirectoryEx. See MSDN for info.

You'll need to #include "shlobj.h" and link your application with shell32.lib.

You could also use PathIsDirectory to check to see if the directory already exists (shlwapi.h / shlwapi.lib)
Nov 2, 2011 at 10:21am
Thanks for the anwer i will check it.
Nov 2, 2011 at 12:19pm
You should check the source code of the open-source libraries such as wxWidgets and Qt, and you could also write a function that takes a path to the last directory to create (e.g. "c:\A\B\C") and that splits the path into the several directories (e.g. "c:\A", "C:\A\B" and "C:\A\B\C") and create them one-by-one.

You shoud also find a way to make it cross-platform because your code is Windows-Specific.
For this, you can use symbols such as #if defined(WINDOWS)
Nov 3, 2011 at 3:22pm
Thanks ;).
Topic archived. No new replies allowed.