How about adding a new method to File that mimics File.createTemp() but creates a directory instead? I've wanted this a couple of times now:
**
** Create a temporary directory which is guaranteed to be a new, empty
** directory with a unique name. The dir name will be generated using
** the specified prefix and suffix.
**
** Examples:
** File.createTemp("x", "-etc") => `/tmp/x67392-etc/`
** File.createTemp.deleteOnExit => `/tmp/fan5284/`
**
static File createTempDir(Str prefix := "fan", Str suffix := ".tmp", File? dir := null)
SlimerDude Tue 23 Jun 2015
How about adding a new method to
Filethat mimicsFile.createTemp()but creates a directory instead? I've wanted this a couple of times now:** ** Create a temporary directory which is guaranteed to be a new, empty ** directory with a unique name. The dir name will be generated using ** the specified prefix and suffix. ** ** Examples: ** File.createTemp("x", "-etc") => `/tmp/x67392-etc/` ** File.createTemp.deleteOnExit => `/tmp/fan5284/` ** static File createTempDir(Str prefix := "fan", Str suffix := ".tmp", File? dir := null)The current workaround is a little awkward:
tempFile := File.createTemp("x-", "-etc") dirName := tempFile.name tempFile.delete tempDir := Env.cur.tempDir.createDir(dirName)brian Tue 23 Jun 2015
That maps to the java.io.File.createTempFile method, I don't think there is any corresponding Java implementation for creating a directory
SlimerDude Tue 23 Jun 2015
Oh, you mean this
createTempFile()method!Fair enough, but it doesn't stop Fantom, being a layer on top of Java, from having its own
createTempDirmethod.It is quite well discussed on StackOverflow in Create a temporary directory in Java with solutions popping up for: