473,396 Members | 2,020 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,396 software developers and data experts.

Need Help: C++ Delete Known File

Greetings,

Onwards with the school studying.

Working on a program and need to delete a file from a known location
on the hard drive but cannot get anything I do to work.

I have tried to use the remove function that is included with <cstdio>
but cannot get it to work properly. My reference book has the
following....

int remove(const char *fname);

and I have found information on the internet using the same above
along with an if statement. When it returns -1 it prints out "Not
deleted" and when it returns 0 if prints "deleted".

However, it never deletes the file.

I have tried to use the system("del c:\deleteme.txt"); command as
well. When I have tweaked the above command, it continues to say the
file doesnt exist even though the path it shows is EXACTLY where the
file is.

I hate asking for code, in fact I think there is something in the FAQ
saying not to ask for it.... but can someone set me straight here.
Either I cannot figure out how to use the remove() properly or
something is afu. :)

Thanks gents.
Jul 22 '05 #1
23 8900
On Sun, 09 May 2004 01:53:20 GMT, da Vinci <bl***@blank.com> wrote:
Greetings,

Onwards with the school studying.

Working on a program and need to delete a file from a known location
on the hard drive but cannot get anything I do to work.

I have tried to use the remove function that is included with <cstdio>
but cannot get it to work properly. My reference book has the
following....

int remove(const char *fname);

and I have found information on the internet using the same above
along with an if statement. When it returns -1 it prints out "Not
deleted" and when it returns 0 if prints "deleted".

However, it never deletes the file.

I have tried to use the system("del c:\deleteme.txt"); command as


Try c:\\deleteme.txt, or better yet, the form that would have saved /me/
lots of debugging time if I'd realized it was equivalent, c:/deleteme.txt.
[Note: Usually, I don't notice this kind of bug until I'm single-stepping
my program right up to the system/fopen/ifstream/whatever call, and looking
at the debugger dump of the command string...)
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2
On Sun, 09 May 2004 01:53:20 GMT in comp.lang.c++, da Vinci
<bl***@blank.com> wrote,
I have tried to use the system("del c:\deleteme.txt"); command as


This issue is covered in Marshall Cline's C++ FAQ. See the topic
'[15.16] Why can't I open a file in a different directory such as
"..\test.dat"?" It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

The usual answer to that is the same in C++ as it is in C, and is
covered in Q. 19.17 of Steve Summit's C FAQ. It is always good to
check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3
On Sun, 09 May 2004 06:03:06 GMT, David Harmon <so****@netcom.com>
wrote:
This issue is covered in Marshall Cline's C++ FAQ. See the topic
'[15.16] Why can't I open a file in a different directory such as
"..\test.dat"?" It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

The usual answer to that is the same in C++ as it is in C, and is
covered in Q. 19.17 of Steve Summit's C FAQ. It is always good to
check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html


I have read them.

The issue is not in using a \ or a /. I cannot get it to delete the
file, regardless of what I use.

Example:

#include <cstdio>

int main()
{
if (remove("SEEBELOW") == -1)
perror ("Error deleting file");
else
puts ("File deleted");

return 0;
}

SEEBELOW is the file name and path that I have tried many different
things with. c:/deleteme.txt ../deleteme.txt ect

I have even created that txt file in every directory from c:\ to the
directory where the .exe is at (debug in projects folder).

This code is also right off the net and still doesnt work. I am
clueless on it.
Jul 22 '05 #4

"da Vinci" <bl***@blank.com> wrote in message
news:s5********************************@4ax.com...
On Sun, 09 May 2004 06:03:06 GMT, David Harmon <so****@netcom.com>
wrote:
This issue is covered in Marshall Cline's C++ FAQ. See the topic
'[15.16] Why can't I open a file in a different directory such as
"..\test.dat"?" It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

The usual answer to that is the same in C++ as it is in C, and is
covered in Q. 19.17 of Steve Summit's C FAQ. It is always good to
check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html


I have read them.

The issue is not in using a \ or a /. I cannot get it to delete the
file, regardless of what I use.

Example:

#include <cstdio>

int main()
{
if (remove("SEEBELOW") == -1)
perror ("Error deleting file");
else
puts ("File deleted");

return 0;
}

SEEBELOW is the file name and path that I have tried many different
things with. c:/deleteme.txt ../deleteme.txt ect

I have even created that txt file in every directory from c:\ to the
directory where the .exe is at (debug in projects folder).

This code is also right off the net and still doesnt work. I am
clueless on it.


You're not listening.

remove("c:\\deleteme.txt");

You must also ensure that your operating system is not
preventing the deletion (via e.g. 'permission' settings).
-Mike
Jul 22 '05 #5

"da Vinci" <bl***@blank.com> wrote in message
news:s5********************************@4ax.com...
On Sun, 09 May 2004 06:03:06 GMT, David Harmon <so****@netcom.com>
wrote:
This issue is covered in Marshall Cline's C++ FAQ. See the topic
'[15.16] Why can't I open a file in a different directory such as
"..\test.dat"?" It is always good to check the FAQ before posting.
You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/

The usual answer to that is the same in C++ as it is in C, and is
covered in Q. 19.17 of Steve Summit's C FAQ. It is always good to
check the FAQ before posting. You can get the FAQ at:
http://www.eskimo.com/~scs/C-faq/top.html


I have read them.

The issue is not in using a \ or a /. I cannot get it to delete the
file, regardless of what I use.


Here's the problem. Either you are trying to delete a file you cannot delete
because you don't have the necessary permissions. Or you are making some
sort of silly mistake. It's impossible for anyone but yourself to tell if
the former is the case. And it is impossible for anyone here to tell if the
latter is the case unless you POST THE EXACT CODE THAT DOESN'T WORK. It's
not good enough to post your description of what you think might be going
wrong, or an imprecise description of all the different things you have
tried, as you say you are clueless. Post the exact code, don't type it in,
cut and paste it from your compiler. Then we should get it sorted out pretty
quickly.

Also might help to mention what operating system and compiler you are using.

john
Jul 22 '05 #6
On 9 May 2004 07:09:33 GMT, "John Harrison"
<jo*************@hotmail.com> wrote:
Here's the problem. Either you are trying to delete a file you cannot delete
because you don't have the necessary permissions. Or you are making some
sort of silly mistake. It's impossible for anyone but yourself to tell if
the former is the case. And it is impossible for anyone here to tell if the
latter is the case unless you POST THE EXACT CODE THAT DOESN'T WORK. It's
not good enough to post your description of what you think might be going
wrong, or an imprecise description of all the different things you have
tried, as you say you are clueless. Post the exact code, don't type it in,
cut and paste it from your compiler. Then we should get it sorted out pretty
quickly.

Also might help to mention what operating system and compiler you are using.

john


Sorry, got caught up in the problem and forgot to give the details.

I am running Windows XP Pro SP1 and using Microsoft Visual C++ 6.0
with Visual Studio 6 SP5 update.

Here is an exact paste of the code I am working on. I left everything
I tried in the program and just // off each one as I went on to a new
one. This way you can see what I have tried to do in the past and
where I am at currently. I have also checked the permission settings
on all of the files I placed through out the directories and none of
them are hidden or read only. Unless Windows XP sets another type of
permission that I do not know about (not listed on a right click -
properties) then that is good.

Here is the code:

#include <cstdio>

int main()
{
/*if( remove( "../deleteme.txt" ) == -1 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );*/

//remove("deleteme.txt");
//remove("c:/deleteme.txt");
//remove("../deleteme.txt");
//remove("c:\\deleteme.txt");
//remove("c:\deleteme.txt");

remove("/deleteme.txt");

return 0;

}
Jul 22 '05 #7
> However, it never deletes the file.

If it remove returns -1, remember to use errno
(I will assume using std somewhere...)
Eg.

#include <cerrno>
....
if(-1 == remove(filename))
{
cout<<"Could not delete: "<<filename<<" due to: "
<<strerror(errno)<<endl;
}
....
This shoudl tell you why, and the output of the filename might also tell
you something about the way you construct your filename array...

Let mw know how it goes

Jorge L.
Jul 22 '05 #8

"da Vinci" <bl***@blank.com> wrote in message
news:4a********************************@4ax.com...
On 9 May 2004 07:09:33 GMT, "John Harrison"
<jo*************@hotmail.com> wrote:
Here's the problem. Either you are trying to delete a file you cannot deletebecause you don't have the necessary permissions. Or you are making some
sort of silly mistake. It's impossible for anyone but yourself to tell if
the former is the case. And it is impossible for anyone here to tell if thelatter is the case unless you POST THE EXACT CODE THAT DOESN'T WORK. It's
not good enough to post your description of what you think might be going
wrong, or an imprecise description of all the different things you have
tried, as you say you are clueless. Post the exact code, don't type it in,cut and paste it from your compiler. Then we should get it sorted out prettyquickly.

Also might help to mention what operating system and compiler you are using.
john

Sorry, got caught up in the problem and forgot to give the details.

I am running Windows XP Pro SP1 and using Microsoft Visual C++ 6.0
with Visual Studio 6 SP5 update.

Here is an exact paste of the code I am working on. I left everything
I tried in the program and just // off each one as I went on to a new
one. This way you can see what I have tried to do in the past and
where I am at currently. I have also checked the permission settings
on all of the files I placed through out the directories and none of
them are hidden or read only. Unless Windows XP sets another type of
permission that I do not know about (not listed on a right click -
properties) then that is good.


Oh yes, Windows XP has lots of other types of permissions. Right click -
permissions - security tab.

Here is the code:

#include <cstdio>

int main()
{
/*if( remove( "../deleteme.txt" ) == -1 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );*/

//remove("deleteme.txt");
//remove("c:/deleteme.txt");
//remove("../deleteme.txt");
//remove("c:\\deleteme.txt");
//remove("c:\deleteme.txt");

remove("/deleteme.txt");

return 0;

}


Well I tried all your variations and they all work for except
"c:\deleteme.txt" which is wrong (should be \\ not \). They don't all delete
files in the same directory mind you, but when I put a file in the right
place it deletes it.

So we have a bit of a mystery. The one thing you haven't said yet which
might help is what error message you get from the perror call.

Here's some possiblities, but none seem very likely

1) You don't have the permissions to delete the file. Since you seem to be
creating the file this seems unlikely. But try deleteing the file from the
desktop, if you can do that, then a program you run should also be able to
delete the file.

2) Some other program has the file open. For instance maybe you are using an
editor to create the file but you haven't closed down that editor before you
try to delete the file.

3) In all your different attempts with files in different places you haven't
managed to get the combination of file location and program code correct
yet.

Another issue, can you delete a file when its in the same directory as your
program code? I.e. when you just try

remove("deleteme.txt");

and deleteme.txt is in the same place as the code above.

Another thing to try, use this code

#include <windows.h>

int main()
{
DWORD err_code = 0;
if (!DeleteFile("c:\\deleteme.txt"))
err_code = GetLastError();
}

I'd be interested to know whether this program deletes the file, and if not
what the value of err_code is.

john
Jul 22 '05 #9
>
1) You don't have the permissions to delete the file. Since you seem to be
creating the file this seems unlikely. But try deleteing the file from the
desktop, if you can do that, then a program you run should also be able to
delete the file.

2) Some other program has the file open. For instance maybe you are using an editor to create the file but you haven't closed down that editor before you try to delete the file.

3) In all your different attempts with files in different places you haven't managed to get the combination of file location and program code correct
yet.


Another possibility

4) You think you are compiling the code you posted but in fact you've made
some mistake in your project settings somewhere and in fact you're compiling
and running a completely different program.

When things seem insane you need to run a few sanity checks.

john
Jul 22 '05 #10
>
Oh yes, Windows XP has lots of other types of permissions. Right click -
permissions - security tab.


Right click - properties - security tab.

john

Jul 22 '05 #11
On Sun, 09 May 2004 14:37:03 GMT, da Vinci <bl***@blank.com> wrote:
I am running Windows XP Pro SP1 and using Microsoft Visual C++ 6.0
with Visual Studio 6 SP5 update.

Here is an exact paste of the code I am working on. I left everything
I tried in the program and just // off each one as I went on to a new
one. This way you can see what I have tried to do in the past and
where I am at currently. I have also checked the permission settings
on all of the files I placed through out the directories and none of
them are hidden or read only. Unless Windows XP sets another type of
permission that I do not know about (not listed on a right click -
properties) then that is good.

Here is the code:

#include <cstdio>

int main()
{
/*if( remove( "../deleteme.txt" ) == -1 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );*/

//remove("deleteme.txt");
//remove("c:/deleteme.txt");
//remove("../deleteme.txt");
//remove("c:\\deleteme.txt");
//remove("c:\deleteme.txt");

remove("/deleteme.txt");

return 0;

}


You might try just "fopen"-ing the file first and see if that succeeds.
That will tell you if the basic pathname is being processed as you expect.
Of course, close it before attempting to delete it.

Also, have you tested by creating a new file and then immediately trying to
delete it? That would eliminate possibilities such as the file being held
open, having weird permissions, etc. I'd try that both by creating the file
outside of the program, and also by creating it /within/ the program (e.g.,
using fopen/fputs/fclose to create it first), just to see if the two behave
any differently.

Good luck,
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #12
On 9 May 2004 15:22:01 GMT, "John Harrison"
<jo*************@hotmail.com> wrote:
#include <windows.h>

int main()
{
DWORD err_code = 0;
if (!DeleteFile("c:\\deleteme.txt"))
err_code = GetLastError();
}


I ran this code and the only thing it says is "Press any key to
continue". There are no error codes or anything else displayed.

The file is still there though.

In reply to another post: I have no security tab. All I have is Right
Click > Properties > General / Summary tabs. I am logged in as an
administrator with full access on the computer. I have ensured that
the read only and hidden blocks are unchecked and went into the
'advanced' area and made sure everything was good there.

It works for you and not me.... that is frustrating!!
Jul 22 '05 #13

"DaVinci" <Da*****@history.com> wrote in message
news:ve********************************@4ax.com...
On 9 May 2004 15:22:01 GMT, "John Harrison"
<jo*************@hotmail.com> wrote:
#include <windows.h>

int main()
{
DWORD err_code = 0;
if (!DeleteFile("c:\\deleteme.txt"))
err_code = GetLastError();
}


I ran this code and the only thing it says is "Press any key to
continue". There are no error codes or anything else displayed.


Well no, you have to add a print statement

#include <windows.h>
#include <cstdio> // add this

int main()
{
DWORD err_code = 0;
if (!DeleteFile("c:\\deleteme.txt"))
err_code = GetLastError();
printf("error code = %lu\n", err_code); // add this
}

Sorry I didn't think I would have to spell that out.

What about the error message you get from your original code?

if( remove( "../deleteme.txt" ) == -1 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );

That should tell you something useful.

john
Jul 22 '05 #14
the remove function calls system functions, such as "del". Does it work in a
dos box, when you try to delete a file ? Maybe your PATH environnement
variable is not set to the windows system ?
Jul 22 '05 #15

"Jean Charbonneau" <ki*******@caramail.com> wrote in message
news:40***********************@news.free.fr...
the remove function calls system functions, such as "del". Does it work in a dos box, when you try to delete a file ? Maybe your PATH environnement
variable is not set to the windows system ?

On my system (which is MSVC++ 7.1 so not the same as the OP's) remove calls
the Windows API function DeleteFile, which is why I advised the OP do to the
same.

I'd be very surprised if the remove API call required a correct PATH
environment variable to work, but maybe the OP could give it a try.

john
Jul 22 '05 #16

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2g**********@uni-berlin.de...

"Jean Charbonneau" <ki*******@caramail.com> wrote in message
news:40***********************@news.free.fr...
the remove function calls system functions, such as "del". Does it work
in a
dos box, when you try to delete a file ? Maybe your PATH environnement
variable is not set to the windows system ?
On my system (which is MSVC++ 7.1 so not the same as the OP's) remove

calls the Windows API function DeleteFile, which is why I advised the OP do to the same.

I'd be very surprised if the remove API call required a correct PATH
environment variable to work, but maybe the OP could give it a try.

john


I was wondering after reading the remove doc which is there ->
http://www.cplusplus.com/ref/cstdio/remove.html

It says "It is compiled as a call to the system function for deleting files
(unlink, erase or del)."

I understand then, that it calls the del on windows environnement, and
therefore I was wondering if then depending on the PATH value, that call
would work or not, tell me if I'm wrong, I'm a beginner somehow.
Jul 22 '05 #17
On Mon, 10 May 2004 13:30:26 +0200, "Jean Charbonneau"
<ki*******@caramail.com> wrote:

I was wondering after reading the remove doc which is there ->
http://www.cplusplus.com/ref/cstdio/remove.html

It says "It is compiled as a call to the system function for deleting files
(unlink, erase or del)."

I understand then, that it calls the del on windows environnement, and
therefore I was wondering if then depending on the PATH value, that call
would work or not, tell me if I'm wrong, I'm a beginner somehow.


I think you're confusing "system calls" (either when they're invoked
directly from a C/C++ program, or as a result of running command
interpreters' "built-in" commands such as cd on Win/Unix, del on Windows,
etc.) with the running of "external" or "transient" commands. Since, under
Windows, even the command line's "del" is built in to the command
processor, it wouldn't rely on the setting of PATH (which, under Windows,
is used primarily to locate executable commands in the case when they're
not present in the current working directory). In any case, library
functions such as "remove" would never in their right mind invoke a
command processor, since removing is a system API facility that can be
invoked directly via a direct API call...again, without any use for the
PATH setting. In fact, I doubt any library functions ever have any need to
invoke the command processor, with the exception of those designed
specifically for the purpose of invoking a command processor with various
configurations of arguments. Those, such as system(), would be the only
ones that the PATH setting might affect.
-leor
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #18
On 9 May 2004 20:26:43 GMT, "John Harrison"
<jo*************@hotmail.com> wrote:
#include <windows.h>
#include <cstdio> // add this

int main()
{
DWORD err_code = 0;
if (!DeleteFile("c:\\deleteme.txt"))
err_code = GetLastError();
printf("error code = %lu\n", err_code); // add this
}


On this code, I get an error code of 2.

I was thinking the same on the print statement needing to be added but
at this point, I didnt want to mess with anything. Seeing as how this
'should' be working and it isnt, I wanted to do exactly as you said to
see if we could get it figured out.

As for the original code you asked about.....

if( remove( "c:/deleteme.txt" ) == -1 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );

I always get a "No such file or directory" error. However, as I said
before, I have that file in every directory from C:\ all the way to
the debug folder where the .exe is being compiled and executed.
Jul 22 '05 #19

"DaVinci" <Da*****@history.com> wrote in message
news:9k********************************@4ax.com...
On 9 May 2004 20:26:43 GMT, "John Harrison"
<jo*************@hotmail.com> wrote:
#include <windows.h>
#include <cstdio> // add this

int main()
{
DWORD err_code = 0;
if (!DeleteFile("c:\\deleteme.txt"))
err_code = GetLastError();
printf("error code = %lu\n", err_code); // add this
}


On this code, I get an error code of 2.

I was thinking the same on the print statement needing to be added but
at this point, I didnt want to mess with anything. Seeing as how this
'should' be working and it isnt, I wanted to do exactly as you said to
see if we could get it figured out.

As for the original code you asked about.....

if( remove( "c:/deleteme.txt" ) == -1 )
perror( "Error deleting file" );
else
puts( "File successfully deleted" );

I always get a "No such file or directory" error. However, as I said
before, I have that file in every directory from C:\ all the way to
the debug folder where the .exe is being compiled and executed.


Well, what can I say, error code 2 means "The system cannot find the file
specified", perror says basically the same.

I'm stumped I'm afraid. However this is very clearly a Windows issue not a
C++ issue, there is nothing wrong with your code from a C++ point of view.
Perhaps you could ask again on a Windows programming group like
news:comp.os.ms-windows.programmer.win32. Someone with more Windows
expertise might be able to answer.

If I think of anything I'll post again.

john
Jul 22 '05 #20
"Leor Zolman" <le**@bdsoft.com> wrote in message news:c7********************************@4ax.com...
I think you're confusing "system calls" (either when they're invoked
directly from a C/C++ program, or as a result of running command
interpreters' "built-in" commands such as cd on Win/Unix, del on Windows,
etc.) with the running of "external" or "transient" commands. Since, under
Windows, even the command line's "del" is built in to the command
processor, it wouldn't rely on the setting of PATH (which, under Windows,
is used primarily to locate executable commands in the case when they're
not present in the current working directory). In any case, library
functions such as "remove" would never in their right mind invoke a
command processor, since removing is a system API facility that can be
invoked directly via a direct API call...again, without any use for the
PATH setting. In fact, I doubt any library functions ever have any need to
invoke the command processor, with the exception of those designed
specifically for the purpose of invoking a command processor with various
configurations of arguments. Those, such as system(), would be the only
ones that the PATH setting might affect.
-leor
--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html


Yes you are totally right, I had a confusion there, thank you for making it
clearer!
Jul 22 '05 #21
If you have been following this thread, John figured it out.

I had the 'Hide extensions of known types' turned on. So, when I
created deleteme.txt I actually created deleteme.txt.txt

I just started doing all my programming on my laptop which had the
hide files extensions turned on. If only I would have tried it on my
desktop.

Thanks for all your help gents. It is good to know help is available
when it is needed...
Jul 22 '05 #22
Without reading through the entire thread, I suspect
the problem is you are not in the correct directory
to remove the file - if you are running your program
in VC++, the program is actually run in the debug or release
directory under your project - please check that or
put the file you want to delete in the debug/release directory
and try that.

Hope that helps!

dave
"da Vinci" <bl***@blank.com> wrote in message
news:fh********************************@4ax.com...
Greetings,

Onwards with the school studying.

Working on a program and need to delete a file from a known location
on the hard drive but cannot get anything I do to work.

I have tried to use the remove function that is included with <cstdio>
but cannot get it to work properly. My reference book has the
following....

int remove(const char *fname);

and I have found information on the internet using the same above
along with an if statement. When it returns -1 it prints out "Not
deleted" and when it returns 0 if prints "deleted".

However, it never deletes the file.

I have tried to use the system("del c:\deleteme.txt"); command as
well. When I have tweaked the above command, it continues to say the
file doesnt exist even though the path it shows is EXACTLY where the
file is.

I hate asking for code, in fact I think there is something in the FAQ
saying not to ask for it.... but can someone set me straight here.
Either I cannot figure out how to use the remove() properly or
something is afu. :)

Thanks gents.

Jul 22 '05 #23
"da Vinci" <bl***@blank.com> wrote:
Working on a program and need to delete a file from a known location
on the hard drive but cannot get anything I do to work.
That's more an OS thing than a C++ thing. Assuming
you're on Windows, this works:

system("erase C:\\MyDir\\MyFile.bmp");

Note the double "\\". More on this later...
I have tried to use the system("del c:\deleteme.txt");
Eww. The '\' character is an escape. To get an actual
'\' character, you have to use a double \\, like this:

system("del c:\\deleteme.txt");

(Though I prefer the equivalent DOS command "erase";
a matter of personal choice.)
When I have tweaked the above command, it continues to say
the file doesnt exist even though the path it shows is EXACTLY
where the file is.


When I try to use the path you give, my compiler screams
"Warning: unknown escape sequence".

Try:

std::cout << "del c:\deleteme.txt" << std::endl;

I'll bet it doesn't print the '\' at all.

Some file-removing functions that come with compilers
work with forward slant bars, like this:

remove("D:/MyDir/MySubDir/MyFile.txt");

You might want to try that format with your "remove"
function.

--
Cheers,
Robbie Hatley
Tustin, CA, USA
email: lonewolfintj at pacbell dot net
web: home dot pacbell dot net slant earnur slant


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Jul 22 '05 #24

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: MattP | last post by:
Ok, with the help of some examples found on the web and some minor modifications on our own, we have a simple and working encrypt and decrypt solution. It runs as a service, watches for files with...
15
by: Roy Smith | last post by:
I understand that "delete xp" deletes a scalar object and "delete xp" deletes an array of objects, but what I don't understand is why you need to tell the compiler which you're doing. When you...
7
by: Christian Christmann | last post by:
Hi, in the past I always appreciated your help and hope that you also can help me this time. I've spent many many hours but still can't solve the problem by myself and you are my last hope. ...
3
by: Joe | last post by:
Hi, I have written a webpage that allows a user to delete files in asp.net with I am having a small problem. To access this page a user has to login via login.aspx page. After successful...
1
by: Chris | last post by:
We had an application running on a server that had been working for months with no problem. Last night, without any known change to the server, it started to fail. We tried all kinds of...
1
by: prabhupr | last post by:
Hi Folks I'm using VS 2005 RTM version. I created a small web-site, added mater pages (2 of them, by mistake). When I try deleting the 2nd master page, its takes for ever to delete that...
2
by: Murali | last post by:
Hello Everyone, I am breaking my head with this problem. Please help me out. Let me first explain my problem : Here it is: I am working in realtime environment where i will be creating...
46
by: Bruce W. Darby | last post by:
This will be my very first VB.Net application and it's pretty simple. But I've got a snag in my syntax somewhere. Was hoping that someone could point me in the right direction. The history: My...
3
by: Dave | last post by:
Using ASP.Net 2.0 on Vista with IIS6, if I set a CacheDependency on a file into a Cache entry that I insert and then delete a subdirectory in the same directory that the file is located in then my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.