Logo

Programming-Idioms

History of Idiom 139 > diff from v2 to v3

Edit summary for version 3 by BBaz:
New D implementation by user [BBaz]

Version 2

2016-07-13, 13:38:15

Version 3

2016-08-14, 05:36:14

Idiom #139 Create temp directory

Create a new temporary folder on filesystem, for writing.

Idiom #139 Create temp directory

Create a new temporary folder on filesystem, for writing.

Code
string mkTmpDir()
{
    import std.uuid, std.file, std.path;
    string d = tempDir ~ dirSeparator ~ randomUUID.toString;
    if (!d.exists)
    {
        mkdir(d);
        return d;
    }
    else return null;
}

string s;
while (!s.length)
  s = mkTmpDir;
Comments bubble
The standard library doesn't provide a function for that.
mkTmpDir generates a folder in the temp dir that takes a UUID as name. THe function succeeds when a non empty string is returned.