944,184 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 5933
  • C++ RSS
Feb 17th, 2005
0

Can't delete file on harddrive!

Expand Post »
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...

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6. int APIENTRY WinMain(HINSTANCE hInstance,
  7. HINSTANCE hPrevInstance,
  8. LPSTR lpCmdLine,
  9. int nCmdShow);
  10.  
  11. int main()
  12. {
  13. cout <<"Deleting file...";
  14.  
  15. system("del C:\Program Files\filedel.txt");
  16.  
  17. MessageBox(NULL, "File Deleted!", "Alert!", NULL);
  18. return 0;
  19. }

If you guys could give me any ideas or suggestions i would greatly appreciate it. thx.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
bombe is offline Offline
14 posts
since Feb 2005
Feb 17th, 2005
0

Re: Can't delete file on harddrive!

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.
Reputation Points: 10
Solved Threads: 1
Light Poster
Intel is offline Offline
30 posts
since Feb 2005
Feb 17th, 2005
0

Re: Can't delete file on harddrive!

Quote originally posted by bombe ...
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...

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <windows.h>
  4. using namespace std;
  5.  
  6. int APIENTRY WinMain(HINSTANCE hInstance,
  7. HINSTANCE hPrevInstance,
  8. LPSTR lpCmdLine,
  9. int nCmdShow);
  10.  
  11. int main()
  12. {
  13. cout <<"Deleting file...";
  14.  
  15. system("del C:\Program Files\filedel.txt");
  16.  
  17. MessageBox(NULL, "File Deleted!", "Alert!", NULL);
  18. return 0;
  19. }

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
steveh is offline Offline
15 posts
since Nov 2004
Nov 29th, 2008
0

Re: Can't delete file on harddrive!

i can't apply this at Borland C
Reputation Points: 10
Solved Threads: 0
Newbie Poster
permoda is offline Offline
1 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: not executing an input from fstream
Next Thread in C++ Forum Timeline: Rapid XOR'ed encryption cracking.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC