Boost logo

Boost Users :

Subject: Re: [Boost-users] file system create directory permissions problem in windows
From: Martin Dyring-Andersen (mda_at_[hidden])
Date: 2011-11-10 03:13:14


> I am trying to create a directory in my temp folder in windows.
> Using this sintax :
>
>       boost::filesystem::remove_all(tcd);
>       boost::filesystem::create_directory(boost::filesystem::path(tcd));
>
> tcd is a char* that looks like :
>
> "%TEMP%\file_123456"
>
> I get the error "the system can not find the patch"

Hi Jose,

I haven't personally used environment variables with boost::filesystem and can't find any mention of it in the documentation. So I would assume that it is not supported.

You'll probably need to expand the environment variables in the path before it to boost::filesystem. Alternatively, if you're only using %TEMP% to determine the temp folder, you might as well use temp_directory_path():

boost::filesystem::path tcd = boost::filesystem::temp_directory_path() / "file_123456";

Also keep in mind that remove_all() will throw if the directory does not exist. Either use the non-throwing remove_all() or check if the directory exists using is_directory().

-- 
Best regards,
Martin Dyring-Andersen
SPAMfighter ApS

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net