开发者

Creating a temporary folder in tmp folder on OS X

How can i create a temporary folder in tmp folder using C++ langu开发者_C百科age.

I have 3 volumes. Leopard, Development and 10.6 (in Mac OS X) and I want to create a temp directory in current home directory.

Here is my code. I am confused about this line char* tempdir = "/Volumes/Development/NewFolder.XXXXXX":

if (!mkdtemp(tempdir)) 

   fprintf(stderr, "Not able to create directory"); 


Under POSIX, you can use mkdtemp to create a directory with a unique name. On Windows, use GetTempPath to retrieve the name of the temp directory, then create a directory with a random name there.


You can use the boost::Filesystem library function: create_directory( "temp" );

This is very portable and will work under most operating systems.

Boost can be downloaded here.


Boost is an excellent choice, but one of the problems with boost is that you would probably be downloading a huge amount of sources - if all you need is the filesystem functionality this is a bit of an overkill. Try http://stlplus.sourceforge.net/stlplus3/docs/file_system.html

Also why don't you just use the good old system() function? The string argument to system of course would be platform dependent.

Arpan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜