title: C++ How do I create a timestamped directory using a filepath held in a string?
body: <p>I am trying to set up a program which can create a new directory every time it is used to fill with data. I want the name of the folder to be a timestamp of when it was created. I have already written a function which creates the timestamp and returns it as a string.</p>
  
  <pre><code>string timestamp() {
  
  //create a timecode specific folder
  // current date/time based on current system
  time_t now = time(0);
  
  struct tm timeinfo;
  localtime_s(&amp;timeinfo, &amp;now);
  
  // print various components of tm structure.
  cout &lt;&lt; "Year: " &lt;&lt; 1900 + timeinfo.tm_year &lt;&lt; endl;
  int Y = 1900 + timeinfo.tm_year;
  cout &lt;&lt; "Month: " &lt;&lt; 1 + timeinfo.tm_mon &lt;&lt; endl;
  int M = 1 + timeinfo.tm_mon;
  cout &lt;&lt; "Day: " &lt;&lt; timeinfo.tm_mday &lt;&lt; endl;
  int D = timeinfo.tm_mday;
  cout &lt;&lt; "Time: " &lt;&lt; 1 + timeinfo.tm_hour &lt;&lt; ":";
  int H = timeinfo.tm_hour;
  cout &lt;&lt; 1 + timeinfo.tm_min &lt;&lt; ":";
  int Mi = timeinfo.tm_min;
  cout &lt;&lt; 1 + timeinfo.tm_sec &lt;&lt; endl;
  int S = 1 + timeinfo.tm_sec;
  
  string timestampStr;
  stringstream convD, convM, convY, convH, convMi, convS;
  convD &lt;&lt; D;
  convM &lt;&lt; M;
  convY &lt;&lt; Y;
  convH &lt;&lt; H;
  convMi &lt;&lt; Mi;
  convS &lt;&lt; S;
  cout &lt;&lt; "Timestamp:" &lt;&lt; endl;
  timestampStr = convD.str() + '.' + convM.str() + '.' + convY.str() + '-' + convH.str() + ':' + convMi.str() + ':' + convS.str();
  cout &lt;&lt; timestampStr &lt;&lt; endl;
  
  return timestampStr;
  }
  </code></pre>
  
  <p>This bit works fine and gives me a string with the current timestamp. I also have a second string with the path to the folders location which I combine to give the full path and new folder name in a string eg "C:\\Users\\Daniel\\Documents\\VS17\\25.5.2017-16:47:51" </p>
  
  <p>I know I can use</p>
  
  <pre><code>CreateDirectory(direc, NULL);
  </code></pre>
  
  <p>to make a directory when I have a file path like the one held in my string but in LPCWSTR format. So really my question is</p>
  
  <ul>
  <li><p>How do I convert my string into a LPCWSTR format to use in CreateDirectory</p></li>
  <li><p>Is there some other way I am just missing</p></li>
  </ul>