Click here to Skip to main content
15,904,416 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Run an exe from MFC app Pin
Hamid_RT31-Jul-07 21:14
Hamid_RT31-Jul-07 21:14 
Questionpost thread message() Pin
shakumar_2230-Jul-07 3:59
shakumar_2230-Jul-07 3:59 
AnswerRe: post thread message() Pin
Iain Clarke, Warrior Programmer30-Jul-07 4:20
Iain Clarke, Warrior Programmer30-Jul-07 4:20 
GeneralRe: post thread message() Pin
shakumar_2230-Jul-07 4:38
shakumar_2230-Jul-07 4:38 
GeneralRe: post thread message() Pin
Iain Clarke, Warrior Programmer30-Jul-07 5:06
Iain Clarke, Warrior Programmer30-Jul-07 5:06 
QuestionHow to put an MFC Dialog box project into another existing project Pin
vladimir7230-Jul-07 2:29
vladimir7230-Jul-07 2:29 
AnswerRe: How to put an MFC Dialog box project into another existing project Pin
Nelek30-Jul-07 2:40
protectorNelek30-Jul-07 2:40 
GeneralRe: How to put an MFC Dialog box project into another existing project Pin
vladimir7230-Jul-07 2:51
vladimir7230-Jul-07 2:51 
GeneralRe: How to put an MFC Dialog box project into another existing project Pin
Hans Dietrich30-Jul-07 3:12
mentorHans Dietrich30-Jul-07 3:12 
AnswerRe: How to put an MFC Dialog box project into another existing project Pin
vladimir7230-Jul-07 3:58
vladimir7230-Jul-07 3:58 
GeneralRe: How to put an MFC Dialog box project into another existing project Pin
Nelek30-Jul-07 20:23
protectorNelek30-Jul-07 20:23 
Questionre: Fast Searching... Pin
Bryster30-Jul-07 1:54
Bryster30-Jul-07 1:54 
AnswerRe: re: Fast Searching... Pin
Randor 30-Jul-07 1:58
professional Randor 30-Jul-07 1:58 
GeneralRe: re: Fast Searching... Pin
Bryster30-Jul-07 2:25
Bryster30-Jul-07 2:25 
AnswerRe: re: Fast Searching... Pin
Hans Dietrich30-Jul-07 3:17
mentorHans Dietrich30-Jul-07 3:17 
GeneralRe: re: Fast Searching... Pin
Bryster30-Jul-07 4:12
Bryster30-Jul-07 4:12 
Questionre: Problems with Progress Bar Pin
Bryster30-Jul-07 1:25
Bryster30-Jul-07 1:25 
AnswerRe: re: Problems with Progress Bar Pin
Hans Dietrich30-Jul-07 3:21
mentorHans Dietrich30-Jul-07 3:21 
GeneralRe: re: Problems with Progress Bar Pin
Bryster30-Jul-07 4:24
Bryster30-Jul-07 4:24 
AnswerRe: re: Problems with Progress Bar Pin
krmed30-Jul-07 4:53
krmed30-Jul-07 4:53 
QuestionRe: re: Problems with Progress Bar Pin
Mark Salsbery30-Jul-07 6:20
Mark Salsbery30-Jul-07 6:20 
Questioncan not delete a file Pin
George_George30-Jul-07 0:13
George_George30-Jul-07 0:13 
AnswerRe: can not delete a file Pin
Jonathan [Darka]30-Jul-07 0:18
professionalJonathan [Darka]30-Jul-07 0:18 
GeneralRe: can not delete a file Pin
George_George30-Jul-07 0:23
George_George30-Jul-07 0:23 
GeneralRe: can not delete a file [modified] Pin
Jonathan [Darka]30-Jul-07 0:57
professionalJonathan [Darka]30-Jul-07 0:57 
I think the problem is that the first file you will 'find' is the current folder '.', you will get an access denied if you try to delete this, so you need to exclude both '.' and '..' from your wildcard search, something like this (obviously could be optimised, this is just to show an example):

Also, you could make it recursive if you wanted to delete sub folders too.

int remove_non_empty_directory(const char* path)
{
	WIN32_FIND_DATA FindFileData;
	int rtn;

	HANDLE hFind = FindFirstFile(path, &FindFileData);
	if (hFind == INVALID_HANDLE_VALUE)
	{
		FindClose(hFind);
		return -1;
	}
	else
	{
            bool bDelete = true;
            if((_tcsicmp(FindFileData.cFileName, "..") == 0) || (_tcsicmp(FindFileData.cFileName, ".") == 0))
                bDelete = false;

            if(bDelete) // delete 1st file
            {
		rtn = DeleteFile((LPCSTR)FindFileData.cFileName);
                // .... original error handling code
            }

   	        // List all the other files in the directory and delete all files
	    while (FindNextFile(hFind, &FindFileData) != 0)
            {
                bDelete = true;
                if((_tcsicmp(FindFileData.cFileName, "..") == 0) || (_tcsicmp(FindFileData.cFileName, ".") == 0))
                    bDelete = false;

                if(bDelete)
		    rtn = DeleteFile((LPCSTR)FindFileData.cFileName);

		FindClose(hFind);
	}

	return 0;
}


And change this code:
DeleteFile(&(FindFileData.cFileName));

to this:
DeleteFile((LPCSTR)FindFileData.cFileName);


regards,


-- modified at 7:09 Monday 30th July, 2007


Jonathan Wilkes
Darka[Xanya.net]

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.