Results 1 to 4 of 4

Thread: CreateDirectory

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Posts
    6

    CreateDirectory

    I am just starting with Win32 and have read the Win32 Help.

    I want to simply create a directory on my hard drive and am trying the code below. It compiles without error, but does not create the directory:

    #define WIN_32_LEAN_AND_MEAN

    #include <windows.h>

    int WINAPI WinMain(HINSTANCE hinstance, HINSTANCE hPrevInstance, LPSTR lpcmdline, int ncmdshow)

    {
    char dirname[] = "C:\new";

    int retval = CreateDirectory(dirname, NULL);

    if (retval != 0)
    {
    MessageBox(NULL, "Directory Created", "Success", MB_OK);
    }
    else
    {
    MessageBox(NULL, "Directory Failed", "Failure", MB_OK);

    }
    return (0);
    }

    Can someone suggest why the new directory is not created?

    Thanks

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    You have to escape the slash (put a backslash before it).

    Code:
    char dirname[] = "C:\\new";
    You have to escape it because it thinks you are escaping the n (\n) which means 'newline.'
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 1999
    Posts
    6
    Thanks Wynd,

    I'll re-read Win32 help, it didn't seem too specific on that point, but maybe I didn't read it properly.

    Thanks for the help

    David

  4. #4
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Well, that is basically for all of C and C++, not just Windows stuff.
    Alcohol & calculus don't mix.
    Never drink & derive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width