TechRepublic|Forums|Web Development
by hueristic · about 24 years, 7 months ago
Need working sample code.
by lastorck · about 24 years, 7 months ago
In reply to C++ Sample Code for non-empty Directory
ok, but i didn’t try it. Hope it ll work properly. I use VC++5.0. Good luck!
#include #include #include #include
int MyDelDir(const string& path) { string _path(path + “\\*.*”); WIN32_FIND_DATA data;
HANDLE hd = FindFirstFile(_path.c_str(), &data); if(hd != INVALID_HANDLE_VALUE) do { if(data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) { if(data.cFileName[0] != ‘.’) //not current & up MyDelDir(path + “\\” + data.cFileName); } else { if(!DeleteFile((path + “\\” + data.cFileName).c_str()) break; //error!!! } }while(FindNextFile(hd, &data));
if(GetLastError() != ERROR_NO_MORE_FILES) return 1; //error!!!
if(!FindClose(hd)) return 2; //error!!!
if(!RemoveDirectory(path.c_str())) return 3; //error!!!
return 0; //OK }
Thanx guy.
Get the web's best business technology news, tutorials, reviews, trends, and analysis—in your inbox. Let's start with the basics.
* - indicates required fields
*
Lost your password? Request a new password
Please enter your email adress. You will receive an email message with instructions on how to reset your password.
Check your email for a password reset link. If you didn't receive an email don't forgot to check your spam folder, otherwise contact support.
This will help us provide you with customized content.
Thanks for signing up! Keep an eye out for a confirmation email from our team. To ensure any newsletters you subscribed to hit your inbox, make sure to add newsletters@nl.technologyadvice.com to your contacts list.