[boost.filesystem] remove issue

Hi:
I am using the following code with boost.filesystem:
size_t origsize = strlen(argv[0]) + 1;
size_t convertedChars = 0;
wchar_t wcstring[1024];
mbstowcs_s(&convertedChars, wcstring, origsize, argv[0],
strlen(argv[0]));
boost::filesystem::wpath path(wcstring);
path.filename() =L"compilation date.txt";
if (boost::filesystem::exists(path))
// boost::filesystem::remove(path);
I have defined:
#define BOOST_FILESYSTEM_NO_DEPRECATED
The line that causes probles is:
// boost::filesystem::remove(path);
Anyone got any ideas why this line causes a window error report to be
generated.
For reference I'm including:
#include

Hi!
probably you are trying to remove a directory? If so try using remove_all
instead.
Regards,
Ovanes
On Sun, May 17, 2009 at 11:07 PM, Sean Farrow
Hi: I am using the following code with boost.filesystem: size_t origsize = strlen(argv[0]) + 1; size_t convertedChars = 0; wchar_t wcstring[1024]; mbstowcs_s(&convertedChars, wcstring, origsize, argv[0], strlen(argv[0])); boost::filesystem::wpath path(wcstring); path.filename() =L"compilation date.txt"; if (boost::filesystem::exists(path)) // boost::filesystem::remove(path); I have defined: #define BOOST_FILESYSTEM_NO_DEPRECATED The line that causes probles is: // boost::filesystem::remove(path); Anyone got any ideas why this line causes a window error report to be generated. For reference I'm including: #include
#include <fstream> #include #include #include #include <string> Cheers Sean.

Hi:
I don't think i am, I was under the impression that argv[0] gave me the
full executable path. If not, how do I obtain this.
Cheers
Sean.
_____
From: boost-users-bounces@lists.boost.org
[mailto:boost-users-bounces@lists.boost.org] On Behalf Of Ovanes
Markarian
Sent: 17 May 2009 22:55
To: boost-users@lists.boost.org
Subject: Re: [Boost-users] [boost.filesystem] remove issue
Hi!
probably you are trying to remove a directory? If so try using
remove_all instead.
Regards,
Ovanes
On Sun, May 17, 2009 at 11:07 PM, Sean Farrow

On Mon, May 18, 2009 at 12:03 AM, Sean Farrow
Hi: I don't think i am, I was under the impression that argv[0] gave me the full executable path. If not, how do I obtain this. Cheers Sean.
Oh, sorry, my fault. But in that case you are trying to do smth very strange :) Take a look at the signature of path::filename. It returns a copy of the filename part. You just assign a new value to the temporary string. And than your app tries to delete the executable itself, which is locked by the running process. That's why you get an error. Your intention probably was: path.remove_filename() /= L"compilation date.txt"; if (boost::filesystem::exists(path)) boost::filesystem::remove(path); //should work Regards, Ovanes
participants (2)
-
Ovanes Markarian
-
Sean Farrow