problems using _rmdir()

Apr 30, 2009 at 12:08pm
Hi,
i'm having trouble using _rmdir() It keeps giving an error code 13 (Permission denied) even though i've used _mkdir() to create the directory earlier in the program.

(I'm using Visual C++ v6.0)

If anyone has any ideas any help would be appreciated.
Cheers,
Dave H.
Apr 30, 2009 at 12:28pm
Make sure there are no open files inside the directory. While you're at it, make sure the directory is empty.
Apr 30, 2009 at 12:30pm
helios,
The directory has been emptied and still no joy!
?
Apr 30, 2009 at 2:11pm
Hi,
still trying to get this directory deleted. It must be something i'm doing once i've created the directory, although i dont know what!
Heres a bit of code showing the the bare bones.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
	CreateDirectory("testdir",NULL);

	FILE  *temp_file;
	temp_file = fopen("testdir\\testfile.txt","w");
	for ( int i = 0 ; i < 15 ; ++i)
	fprintf(temp_file,"Line Number %i\n",i);
	fclose(temp_file);
	
	CFileFind Clear;
	BOOL bDelete = Clear.FindFile("testdir\\*");
	while (bDelete)
	{
		bDelete = Clear.FindNextFile();
		DeleteFile(Clear.GetFilePath() );
	}

	RemoveDirectory("testdir");
}

if i comment out the stuff between the CreateDirectory() and RemoveDirectory() the directory gets deleted. Has anyone got any ideas what i'm doing wrong?
Thanks in advance.
Dave H
Apr 30, 2009 at 2:52pm
I'm not familiar with CFileFind. Have you tried the native WIN32 calls FindFirstFile/FindNextFile/FindClose? After all, you're using native calls to create and delete the directory.
Apr 30, 2009 at 4:27pm
CFileFind must have opened a handle to testdir when you opened the directory for searching.
you haven't closed it and are trying to remove the directory.. this might be the problem.

May 5, 2009 at 7:03am
Thanks for that the code below worked a treat!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
	CreateDirectory("testdir",NULL);

	FILE  *temp_file;
	temp_file = fopen("testdir\\testfile.txt","w");
	for ( int i = 0 ; i < 15 ; ++i)
	fprintf(temp_file,"Line Number %i\n",i);
	fclose(temp_file);
	
	CFileFind Clear;
	BOOL bDelete = Clear.FindFile("testdir\\*");
	while (bDelete)
	{
		bDelete = Clear.FindNextFile();
		DeleteFile(Clear.GetFilePath() );
	}
                Clear.Close();

	RemoveDirectory("testdir");
}


ps sorry for the duplicate post ! newbie error.

Cheers,
Dave H
Topic archived. No new replies allowed.