PDA

Click to See Complete Forum and Search --> : How do I delete a file in C++?


Wynd
Dec 16th, 2000, 03:12 PM
Like,
cout<<Type in the file to delete: ";
cin>>filepath;
???

parksie
Dec 16th, 2000, 03:27 PM
Use the remove or unlink functions.

Wynd
Dec 16th, 2000, 03:47 PM
Could you please type in the code for that? I can't figure it out.

parksie
Dec 16th, 2000, 03:50 PM
#include <stdio.h>

/* ... */

remove("autoexec.bat");

Vlatko
Dec 16th, 2000, 07:50 PM
Or this:

BOOL DeleteFile(
LPCTSTR lpFileName // pointer to name of file to delete
);

DeleteFile(filename);

parksie
Dec 17th, 2000, 04:59 AM
That's Windows only ;)

Wynd
Feb 5th, 2001, 06:25 PM
Ok, thanks, I was trying to figure it out in windows but I couldn't do it. Thanks.

sail3005
Feb 6th, 2001, 06:49 PM
can you delete any file with that? like even protected system files? And one more thing, if you used that, would a virus scanner pick it up?

I am not going to write a virus, just wondering how it works.

Wynd
Feb 6th, 2001, 06:52 PM
Yeah, like remove(some important files), will a virus scanner find it? I was wondering, because it is so simple.

Cybrg641
Feb 6th, 2001, 07:17 PM
I don't really know how a virus scanner works, but I am guessing that it monitors only the most important system files. If it monitored every single file, then it would slow the system down considerably. It probably won't do anything if you directly edit them with a text editor or something, but it might pop up if you change them through code. You could try it yourself, but be sure to make a backup of the one you are editing!

sail3005
Feb 6th, 2001, 07:20 PM
yeah, well if you just did a full system scan, would it be able to pick up anything?

PunK
Sep 25th, 2001, 09:43 PM
I cant get it to work....

remove("jim.zip");


It no workie:confused: :confused: :mad:

PunK
Sep 25th, 2001, 09:48 PM
Gah, I spoke too soon. I forgot I had to put remove("C:\\Windows\\Desktop\\f-er.zip");

I was putting:
remove("C:\Windows\Desktop\f-er.zip")
:D :D :D :D :D :rolleyes: :rolleyes: :rolleyes: