
On Thu, 16 Jul 2009 19:33:19 +0100, Craig Henderson wrote:
I cannot find any function in the Boost.Filesystem library to get a temporary filename. There has been some discussion about this functionality on the lists many years ago - did anything come of this? I need a cross-platform way to do this and was hoping boost would provide it :)
I was looking for exactly such a thing just yesterday and was surprised to find that boost::filesystem didn't have one. Here's the function I wrote instead (Windows only) in case it's of any use: wpath TempFilePath() { vector<wchar_t> buffer(MAX_PATH); DWORD len = ::GetTempPath(buffer.size(), &buffer[0]); wstring directory(&buffer[0], buffer.size()); if (!GetTempFileName(directory.c_str(), NULL, 0, &buffer[0])) throw boost::system::system_error( ::GetLastError(), boost::system::system_category); wstring file(&buffer[0], buffer.size()); return wpath(directory) / file; } Alex