Logo

Programming-Idioms

History of Idiom 139 > diff from v7 to v8

Edit summary for version 8 by WebFreak:
[D] buildPath is more idiomatic

Version 7

2017-07-21, 16:39:01

Version 8

2017-07-30, 12:05:44

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.

Extra Keywords
tmp tmpdir tempdir
Extra Keywords
tmp tmpdir tempdir
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;
Code
string mkTmpDir()
{
    import std.uuid, std.file, std.path;
    string d = buildPath(tempDir, 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 temp dir is created when a non empty path is returned.
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 temp dir is created when a non empty path is returned.