Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Create a directory

Create a directory

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomsysadminsecurity
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rage
    wrote on last edited by
    #1

    Hi CPians, following code does work:

    BOOL b4=CreateDirectory("C:\\hop",NULL);

    following does not work (I have deleted the hop previously created by the previous code line, so the start point is the same):

    BOOL b4=CreateDirectory("C:\\hop\\hop\\hop",NULL);

    GetLastError returns 3, which states "The system cannot find the path specified." which is in this especially true, since I would like to create the directory :rolleyes: Does CreateDirectory not support multiple level creation ? If not, are there any alternative solution to it ? Do I have to use specific security attributes ? If yes, how can I retrieve them (like the ones currently set for the system) ? Do you think following is possible with CreateDirectory :

    BOOL b4=CreateDirectory("\\server.hop.com\\hop\\hop",NULL);

    Thanks for all ~RaGE();

    B 1 Reply Last reply
    0
    • R Rage

      Hi CPians, following code does work:

      BOOL b4=CreateDirectory("C:\\hop",NULL);

      following does not work (I have deleted the hop previously created by the previous code line, so the start point is the same):

      BOOL b4=CreateDirectory("C:\\hop\\hop\\hop",NULL);

      GetLastError returns 3, which states "The system cannot find the path specified." which is in this especially true, since I would like to create the directory :rolleyes: Does CreateDirectory not support multiple level creation ? If not, are there any alternative solution to it ? Do I have to use specific security attributes ? If yes, how can I retrieve them (like the ones currently set for the system) ? Do you think following is possible with CreateDirectory :

      BOOL b4=CreateDirectory("\\server.hop.com\\hop\\hop",NULL);

      Thanks for all ~RaGE();

      B Offline
      B Offline
      Bob Ciora
      wrote on last edited by
      #2

      The documentation for CreateDirectory[^] does mention that it will only create the final directory in the specified path (c.f. the comments for ERROR_PATH_NOT_FOUND). There is a suggestion at the MSDN site to use the SHCreateDirectoryEx function. However, the documentation for this function would indicate that it won't work on earlier versions of Windows. The alternative is to parse your path string (for the '\\' or '/' characters) and create the intermediate directories as well. You can use CString to locate the first occurrence of the character, do a SetCurrentDirectory and, if that fails, CreateDirectory. Repeat this process until you've parsed all subdirectories in the path string. Bob Ciora

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups