title: Creating a unique temporary directory from pure C in windows
body: <p>I'd like to create a unique temporary directory in Windows from some C
  code (not C++ or C#). I want to do this so that I can put some temp
  files in the directory, and then delete them all easily when I'm done
  (by removing the directory recursively).</p>
  <p>I'm essentially looking for an equivalent of the linux
  <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/mkdtemp.html" rel="noreferrer"><code>mkdtemp</code></a>
  function. There is a C# answer <a href="https://stackoverflow.com/questions/278439/creating-a-temporary-directory-in-windows">here</a>, and responses on <a href="https://stackoverflow.com/questions/3379956/how-to-create-a-temporary-directory-in-c">this
  question</a>
  suggest using Boost. But since I'm using C, those solutions don't work
  for me.</p>
  <p>The best I've been able to come up with so far is to use
  <a href="http://msdn.microsoft.com/en-us/library/aa364991(v=vs.85).aspx" rel="noreferrer"><code>GetTempFileName</code></a>
  followed by <a href="http://msdn.microsoft.com/en-us/library/aa363855(v=vs.85).aspx" rel="noreferrer"><code>CreateDirectory</code></a>,
  but the problem there is that if I ask
  <a href="http://msdn.microsoft.com/en-us/library/aa364991(v=vs.85).aspx" rel="noreferrer"><code>GetTempFileName</code></a>
  to create a unique file name, it will also create the file (which I
  don't want, since I want to make a directory instead).</p>
  <p>Relatedly, there's
  <a href="http://msdn.microsoft.com/en-us/library/aa364992(v=vs.85).aspx" rel="noreferrer"><code>GetTempPath</code></a>,
  which returns the location of the user's temp folder from environment
  variables - but since I want to create my own directory that I can
  safely delete later, I still need to create a directory inside any
  path it would return.</p>
  <p>It looks like if I want a unique directory to be created, I'll have to
  create a temp file, get the name, delete it, and then create a
  directory with the same name - which sounds very messy.
  Any other ideas?</p>