0

Hi viewers,
I was trying to delete a file from my hard drive and I don't really have a good place to start. I googled it and came up with a code derived from multiple sources. I was wondering if anyone could help me out with the code to delete files from anywhere in your hard drive. Doesn't matter what file it is because this code is for a bigger program i'm trying to create. Here's my code so far...

#include <iostream>
#include <cstdlib>
#include <windows.h>
using namespace std;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow);

int main()
{
cout <<"Deleting file...";

system("del C:\Program Files\filedel.txt");

	MessageBox(NULL, "File Deleted!", "Alert!", NULL);
return 0;
}

If you guys could give me any ideas or suggestions i would greatly appreciate it. thx.

4
Contributors
3
Replies
4
Views
12 Years
Discussion Span
Last Post by permoda
0

Lazy way to do it:
First strore the file name and location in a string. Append to this string 'del ' at the beginning. Execute the 'System' stmt on that string.

0

Hi viewers,
I was trying to delete a file from my hard drive and I don't really have a good place to start. I googled it and came up with a code derived from multiple sources. I was wondering if anyone could help me out with the code to delete files from anywhere in your hard drive. Doesn't matter what file it is because this code is for a bigger program i'm trying to create. Here's my code so far...

#include <iostream>
#include <cstdlib>
#include <windows.h>
using namespace std;

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow);

int main()
{
cout <<"Deleting file...";

system("del C:\Program Files\filedel.txt");

	MessageBox(NULL, "File Deleted!", "Alert!", NULL);
return 0;
}

If you guys could give me any ideas or suggestions i would greatly appreciate it. thx.

You can also use the function FileDelete("path"). "path" is a string containing the filename. This fxn also supports wildcards if you are not sure of the file's extension.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.