Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetTempFileName function for a directory?

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)?

like image 699
Jez Avatar asked Jun 17 '11 10:06

Jez


People also ask

How do I find temporary files?

Find where your temp files are stored by pressing and holding the Windows button, and then hit R to bring up the Run dialogue box. Type temp and press Enter (or click OK) to open up the folder location and see your temp files. Hold Ctrl and click individual items to select them for cleanup.

How do I create a temp folder in Windows?

Open your File Explorer (it's usually the first button on your desktop taskbar, looks like a folder). Go to the "This PC" section on the left, and then double-click your C: drive. On the Home tab at the top, click "New Folder" and name it "Temp".

What is Windows API function GetTempFileName?

GetTempFileName generates a filename for a temporary file and optionally creates it for you. Temporary files are used to store data for short periods of time on the hard drive. The full filename, including the path, is put into the string variable passed as lpTempFileName .

How do I create a tmp file?

To create and use a temporary fileThe application opens the user-provided source text file by using CreateFile. The application retrieves a temporary file path and file name by using the GetTempPath and GetTempFileName functions, and then uses CreateFile to create the temporary file.


1 Answers

You could use Guid.NewGuid().ToString() for that task.

like image 68
DanielB Avatar answered Oct 31 '22 21:10

DanielB