This language bar is your friend. Select your favorite languages!

Idiom #139 Create temp directory

Create a new temporary folder on filesystem, for writing.

extern crate tempdir;
use tempdir::TempDir;
let tmp = TempDir::new("prefix")?;
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;
import "io/ioutil"
dir, err := ioutil.TempDir("", "")
function createTempDir() {    
    $separator = DIRECTORY_SEPARATOR;
    $path = rtrim(sys_get_temp_dir(), $separator) . $separator . mt_rand() . microtime(TRUE);
    $createdTempDir = mkdir($path);
    if ($createdTempDir)
        return $path;
    return FALSE;
}
sysutils
var
  GUID: TGUID;
  Succes: Boolean;

begin
  CreateGUID(GUID);
  Succes := CreateDir(GetTempDir + GUIDToString(GUID));
end.
import tempfile	
td = tempfile.TemporaryDirectory()
require 'tmpdir' 
td = Dir.mktmpdir

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms