•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 392,044 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,252 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1096 | Replies: 2
![]() |
Hello, I have recently been able to delete files using this code(With the aid of others from the forum) And I was wondering how you can change this, to suit deleting a folder
Thank you
cpp Syntax (Toggle Plain Text)
#include <iostream> #include <windows.h> int main(int argc, const char * argv[]) { // Get a pointer to the file name/path const char * pFileToDelete = "c:\\Program Files\\myfile.txt"; // try deleting it using DeleteFile if(DeleteFile(pFileToDelete )) { // succeeded std::cout << "Deleted file" << std::endl; } else { // failed std::cout << "Failed to delete the file" << std::endl; } std::cin.get(); return 0; }
Last edited by WolfPack : Feb 18th, 2008 at 12:04 pm. Reason: Added [CODE=CPP][/CODE] Tags.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,809
Reputation:
Rep Power: 11
Solved Threads: 184
•
•
Join Date: Jan 2008
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
similar to how there are all the windows functions to work with files, there are ones to handle directories.
http://msdn2.microsoft.com/en-us/lib...50(VS.85).aspx
unfortunately there is no direct way, first you must delete all the files within the directory.
for this you need to find all the files in the folder.
microsoft are nice enough to give you this code in an example though.
http://msdn2.microsoft.com/en-us/lib...00(VS.85).aspx
store the filenames in an array of strings or something, loop through that array with deletefile function.
then its simple to use removedirectory function
http://msdn2.microsoft.com/en-us/lib...88(VS.85).aspx
MSDN is your friend =D
Dead.Rabit
http://msdn2.microsoft.com/en-us/lib...50(VS.85).aspx
unfortunately there is no direct way, first you must delete all the files within the directory.
for this you need to find all the files in the folder.
microsoft are nice enough to give you this code in an example though.
http://msdn2.microsoft.com/en-us/lib...00(VS.85).aspx
store the filenames in an array of strings or something, loop through that array with deletefile function.
then its simple to use removedirectory function
http://msdn2.microsoft.com/en-us/lib...88(VS.85).aspx
MSDN is your friend =D
Dead.Rabit
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- hijackthis log... what to delete?? (Viruses, Spyware and other Nasties)
- I cannot delete a folder (error message) (Windows NT / 2000 / XP / 2003)
- Cant delete avi movie file! HELP (Windows NT / 2000 / XP / 2003)
- System 32 Folder (Windows 9x / Me)
- Takes time to copy,cut,paste or delete (Windows 9x / Me)
- Can't delete a folder (Windows NT / 2000 / XP / 2003)
Other Threads in the C++ Forum
- Previous Thread: output window for c++!!! help!!
- Next Thread: Sorting a Structure.



Linear Mode