Code that delete files

Apr 26, 2012 at 10:12pm
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
Apr 26, 2012 at 10:18pm
Apr 26, 2012 at 10:21pm
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.
Apr 26, 2012 at 10:28pm
Visual Studio doesn't accept the code remove by himself.
It says that the command isn't declared.
Apr 26, 2012 at 10:40pm
what program are you writing (gui/console), what IDE are you useing, and whgat compiler...
Apr 26, 2012 at 10:56pm
Did you include <cstdio>?
Did you write std::remove("C:\\text.txt");?
Apr 27, 2012 at 12:43am
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 Apr 28, 2012 at 3:16am
Apr 27, 2012 at 6:26am
I'v tested bouth and doesn't work.
"remove" is never accepted on Vs...
Apr 27, 2012 at 10:20am
"remove" is never accepted on Vs...

Is that an error message or just your claim?
Apr 27, 2012 at 10:44am
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.