General discussion

Locked

C++ Sample Code for non-empty Directory

By Hueristic ·
Need working sample code.

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

C++ Sample Code for non-empty Directory

by lastorck In reply to C++ Sample Code for non-e ...

ok, but i didn't try it. Hope it ll work properly. I use VC++5.0. Good luck!

#include <windows.h>
#include <winbase.h>
#include <iostream>
#include <string>

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
}

Collapse -

C++ Sample Code for non-empty Directory

by Hueristic In reply to C++ Sample Code for non-e ...

Thanx guy.

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums