The .NET Framework defines a System.IO.Path.GetTempFileName method, which guarantees that the temporary filename it generates will be unique. As far as I can tell though, although extremely unlikely, this filename could be identical to the name of a directory at the same path, meaning that I can’t assume that by taking the name of that file, deleting it, and creating a directory of the same name, I’ll have a directory with a unique name to any other directory. Whatsmore, I can’t specify the path under which GetTempFileName should create its temp file. There doesn’t seem to be an equivalent function to GetTempFileName for directories.
Is there a GetTempFileName equivalent for creating a unique directory? If not, what’s the best way to create a unique directory at a specified location (ie. I specify the path under which to create the unique directory)?
You could use
Guid.NewGuid().ToString()for that task.