473,383 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

std::remove

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
3 6244
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
* 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Christopher Armstrong | last post by:
Hello! I'm trying to write a part of a program that will remove all files in its directory. I have tried the std::remove feature of the standard library, but I don't know its syntax. Also, what's...
3
by: Venkat | last post by:
Hi All, Currently i guess rename and remove are not supported using fstream. How do i rename or remove a file? regards, Venkat
2
by: Clement RAMBACH | last post by:
Hi, here is my problem: I have a std::vector< A* >. This vector contains pointers to the objects A i create (lets say about 4000 items). I do this several times in my application, and at the...
18
by: JKop | last post by:
Can some-one please point me to a nice site that gives an exhaustive list of all the memberfunctions, membervariables, operators, etc. of the std::string class, along with an informative...
6
by: Arne Claus | last post by:
Hi If've just read, that remove() on a list does not actually remove the elements, but places them at the end of the list (according to TC++STL by Josuttis). It also says, that remove returns a...
15
by: Andrew Maclean | last post by:
I guess this problem can be distilled down to: How do I search through a string, find the first matching substring, replace it, and continue through the string doing this. Can replace_if() be used...
3
by: groups | last post by:
This small piece of code is troubling me.. is there anything wrong with it?? After calling this method the contents ot the input vector are completely screwed.. (CCountedCIG_CountZero() applies...
13
by: arnuld | last post by:
/* C++ Primer 4/e * section 3.2 - String Standard Library * exercise 3.10 * STATEMENT * write a programme to strip the punctation from the string. */ #include <iostream> #include...
26
by: Brad | last post by:
I'm writing a function to remove certain characters from strings. For example, I often get strings with commas... they look like this: "12,384" I'd like to take that string, remove the comma...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.