Code that delete files

I'm looking for a code that deletes files
(I Mean, I code that can delete C:\text.txt for exemple)
Help plz.
Tnks 4 your time, Heroi
remove("yourfilename.extension");

you can use directories as well:

remove("C:\\Users\\Username\\desktop\\shortcut.lnk");

If you REALLY want to wipe a file that doesnt want to go, you can use shredding algorithms. The basic mechanics goes like this:

open file
write random crap
close file
remove file

if all else fails, you can always try a linux flash drive boot.
Visual Studio doesn't accept the code remove by himself.
It says that the command isn't declared.
what program are you writing (gui/console), what IDE are you useing, and whgat compiler...
Did you include <cstdio>?
Did you write std::remove("C:\\text.txt");?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main ()
{
  cout<< "Write path of file to be deleted: ";
  string s;
  getline(cin, s);

  if( remove( s.c_str()) != 0 )
    perror( "Error deleting file" );
  else
    puts( "File successfully deleted" );
  return 0;
}


this should work...never tested.


EDIT: shoot, thanks Gaminic!
Last edited on
I'v tested bouth and doesn't work.
"remove" is never accepted on Vs...
"remove" is never accepted on Vs...

Is that an error message or just your claim?
Assuming "Vs" is Visual Studio: yes it does.
(The code above by blueberry is missing a ';' on line 8 though.)
Topic archived. No new replies allowed.