954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't delete file on harddrive!

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.

bombe
Newbie Poster
14 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

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.

Intel
Light Poster
30 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

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.

steveh
Newbie Poster
15 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

i can't apply this at Borland C

permoda
Newbie Poster
1 post since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You