在Windows中创建一个临时目录? [英] Creating a temporary directory in Windows?

查看:462
本文介绍了在Windows中创建一个临时目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是获得在Windows临时目录名的最好方法是什么?我看到,我可以使用 GetTempPath GetTempFileName 来创建一个临时文件,但没有任何等同于Linux的/ BSD mkdtemp 函数用于创建一个临时目录?

What's the best way to get a temp directory name in Windows? I see that I can use GetTempPath and GetTempFileName to create a temporary file, but is there any equivalent to the Linux / BSD mkdtemp function for creating a temporary directory?

推荐答案

没有,没有等同于mkdtemp。最好的办法是使用 GetTempPath 和<一组合href="http://msdn.microsoft.com/en-us/library/system.io.path.getrandomfilename.aspx">GetRandomFileName.

No, there is no equivalent to mkdtemp. The best option is to use a combination of GetTempPath and GetRandomFileName.

您将需要code与此类似:

You would need code similar to this:

public string GetTemporaryDirectory()
{
   string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
   Directory.CreateDirectory(tempDirectory);
   return tempDirectory;
}

这篇关于在Windows中创建一个临时目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆