我必须使用哪种 gtk 方法来获取 Ubuntu 中的临时路径?
如何获取Ubuntu中的临时目录路径?
How can I get the temporary directory path in Ubuntu?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何获取Ubuntu中的临时目录路径?
How can I get the temporary directory path in Ubuntu?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(5)
在大多数类 Unix 系统上,您需要查找
/tmp
。如果这不是您想要的答案,您应该指定您正在谈论的 Ubuntu 的哪部分。某些应用程序允许您指定临时文件的放置位置(例如使用
TMP
、TEMP
或TMPDIR
环境变量),但很多如果/tmp
不存在,很多东西都会在 UNIX 下崩溃,所以使用它是安全的。如果您想使其可配置,在您的代码中,您可以在以下完整程序中使用类似函数getTmpDir()
的内容:在我的 CygWin 环境中输出(我有
TEMP
和TMP
设置为此值):这几乎就是 GLib
g_get_tmp_dir()
调用确实如此,尽管可能以不同的顺序。当然,如果您想使用特定于应用程序的环境变量,您可以将其放在其他变量之前:
或者甚至删除部分或全部“标准”变量。但如果用户没有配置任何内容,您几乎应该总是依靠
/tmp
。On most Unix-like systems, you'd be looking for
/tmp
. If that's not quite the answer you were after, you should specify which bit of Ubuntu you're talking about.Certain applications will allow you to specify where their temporary files are put (such as with the
TMP
,TEMP
orTMPDIR
environment variables) but a lot of stuff would break under UNIX if/tmp
didn't exist, so it's safe just to use that. If you want to make it configurable, in your code, you'd use something like the functiongetTmpDir()
in the following complete program:which outputs, in my CygWin environment (I have both
TEMP
andTMP
set to this value):That's pretty much what the GLib
g_get_tmp_dir()
call does, though possibly in a different order.Of course, if you wanted to use an application-specific environment variable, you could put that before the others thus:
Or even take out some or all of the "standard" ones. But you should pretty much always fall back on
/tmp
if the user hasn't configured anything.我查看了 Python 是如何做到这一点的 ,并且似乎没有任何特定的 UNIX 接口可以执行此操作。
他们只是按顺序尝试:
TMPDIR
、TEMP
和TMP
/tmp
/ var/tmp
/usr/tmp
鉴于 Python 是由比我聪明得多的人编写的,我愿意打赌这可能是您能做的最好的事情。
I looked at how Python does this, and there doesn't seem to be any specific UNIX interface to do so.
They just try, in sequence:
TMPDIR
,TEMP
, andTMP
/tmp
/var/tmp
/usr/tmp
Given that Python was written by people a lot smarter than I am, I'd be willing to bet this is probably the best you can do.
Flocks,
感谢您抽出时间,但我期待的是来自 gnome 链接。
http://library.gnome.org/devel/glib /unstable/glib-Miscellaneous-Utility-Functions.html
使用 API g_get_tmp_dir() 我们可以获得临时目录的位置
Flocks,
Thanks for taking your time but what i am expecting is from the gnome link.
http://library.gnome.org/devel/glib/unstable/glib-Miscellaneous-Utility-Functions.html
using the API g_get_tmp_dir() we can have the location of temp directory
有一个环境变量 TMPDIR 可以设置临时目录的位置,大多数程序都尊重这一点,如果未设置它将默认为 /tmp (或 /var/tmp)
There is an environment variable TMPDIR which can set the location of the temporary dir, most programs respect this, if it's not set it will default to /tmp (or /var/tmp)
从命令行:
From the command line: