[Boost-users] file system create directory permissions problem in windows

58 views
Skip to first unread message

Jose

unread,
Nov 9, 2011, 1:15:45 PM11/9/11
to boost-users
Hi,

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"

If I use _mkdir. I also get an error.

Is there anything that I am missing to create directories in the env. variable temp in windows?

The code works just fine in linux.

Thanks

Jose

Martin Dyring-Andersen

unread,
Nov 10, 2011, 3:13:14 AM11/10/11
to boost-users
> 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 mailing list
Boost...@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users

Reply all
Reply to author
Forward
0 new messages