By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,143 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,143 IT Pros & Developers. It's quick & easy.

std::remove

P: n/a
Hi,

I am trying to use std::remove to delete a file and have been
encountering some problems. My goal is to pass std::remove a
std::string and remove the file of that name, for example.

Std::string a = "C:\\Documents and Settings\\a.txt";
Std::remove(a.c_str());

However the process fails and returns error code 267 The directory name
is invalid (the directory defiantly exists as does the file). I figure
I am doing something wrong which is quite simple but it is eluding me!

Thanks for your help

/craig

May 4 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
cr**********@hotmail.com wrote:
I am trying to use std::remove to delete a file and have been
encountering some problems. My goal is to pass std::remove a
std::string and remove the file of that name, for example.

Std::string a = "C:\\Documents and Settings\\a.txt";
Std::remove(a.c_str());

However the process fails and returns error code 267 The directory
name is invalid (the directory defiantly exists as does the file). I
figure I am doing something wrong which is quite simple but it is
eluding me!


Your question cannot be answered in the terms of standard C++ language,
which makes it off-topic. Please ask about the error 267 in the newsgroup
that deals with your os, 'comp.os.ms-windows.programmer' (or below).

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 4 '06 #2

P: n/a
* Victor Bazarov:
cr**********@hotmail.com wrote:
I am trying to use std::remove to delete a file and have been
encountering some problems. My goal is to pass std::remove a
std::string and remove the file of that name, for example.

Std::string a = "C:\\Documents and Settings\\a.txt";
Std::remove(a.c_str());

However the process fails and returns error code 267 The directory
name is invalid (the directory defiantly exists as does the file). I
figure I am doing something wrong which is quite simple but it is
eluding me!


Your question cannot be answered in the terms of standard C++ language,
which makes it off-topic. Please ask about the error 267 in the newsgroup
that deals with your os, 'comp.os.ms-windows.programmer' (or below).


Well, I don't think it's off-topic at all. But let's note for the
record that the C standard, which the C++ standard defers to for this
std::remove (see table 99), doesn't seem to mention that std::remove
should set errno on failure, so possibly the errno value reported by the
OP /could/ be just a spurious value. std::remove indicates success by
returning 0, and failure by returning non-zero (something, I don't
remember from five seconds ago whether it's specified as -1).

Apart from the uppercase 'S' in 'Std' the OP's code is valid, but since
it wouldn't compile as given, we don't know whether the rest is the
actual code -- dear OP, please post /actual/ code the next time.

Also, the OP fails to check the return value of the function call, and
so also the claim about failure is a bit suspect.

If correct, however, it could be that the function fails because the
file to be removed doesn't exist, or can't be removed.

It could also be that the specified directory actually doesn't exist or
is accessible (it exists and is accessible on my computer, and there the
code, with the 'S' corrected, works fine).

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
May 4 '06 #3

P: n/a
Alf P. Steinbach wrote:
* Victor Bazarov:
cr**********@hotmail.com wrote:
I am trying to use std::remove to delete a file and have been
encountering some problems. My goal is to pass std::remove a
std::string and remove the file of that name, for example.

Std::string a = "C:\\Documents and Settings\\a.txt";
Std::remove(a.c_str());

However the process fails and returns error code 267 The directory
name is invalid (the directory defiantly exists as does the file). I
figure I am doing something wrong which is quite simple but it is
eluding me!
Your question cannot be answered in the terms of standard C++
language, which makes it off-topic. Please ask about the error 267
in the newsgroup that deals with your os,
'comp.os.ms-windows.programmer' (or below).


Well, I don't think it's off-topic at all. But let's note for the
record that the C standard, which the C++ standard defers to for this
std::remove (see table 99), doesn't seem to mention that std::remove
should set errno on failure, so possibly the errno value reported by


How do you conclude the OP uses 'errno'? It is quite possible that the
OP uses some OS-specific way (like 'GetLastError' or something) or other
language/library extension. Considering the value ("267"), it is rather
likely, and that's why I suggested that we cannot really discuss those
things here, since they are outside the scope of the language. Had the
OP used the "normal" way of figuring out success or failure of the call,
we might be able to help, but with anything else?...
the OP /could/ be just a spurious value. std::remove indicates
success by returning 0, and failure by returning non-zero (something,
I don't remember from five seconds ago whether it's specified as -1).

[..]


V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
May 4 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.