Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating a unique temporary directory from pure C in windows
    primarykey
    data
    text
    <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="nofollow 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="nofollow noreferrer"><code>GetTempFileName</code></a> followed by <a href="http://msdn.microsoft.com/en-us/library/aa363855(v=vs.85).aspx" rel="nofollow 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="nofollow 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="nofollow 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>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload