Need Help: C++ Delete Known File

J

Jean Charbonneau

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!
 
D

DaVinci

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...
 
D

Dave Townsend

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
 
R

Robbie Hatley

da Vinci said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,173
Messages
2,570,938
Members
47,474
Latest member
VivianStuk

Latest Threads

Top