CreateFile() for Directory

Hi,
I want to open directory from my machine in write mode. So i can delete files from that folder. Will someone help me by giving one example. I also want to know in what situation directory can not be open in write mode...
To delete a read-only file, first you must remove the read-only attribute.
To delete or rename a file, you must have either delete permission on the file, or delete child permission in the parent directory.
To delete files use DeleteFile() API.
To remove empty directories use RemoveDirectory().
To recursively delete the files in a directory, use the SHFileOperation() function.
k, u gave very nice reply.
I have one problem. I want to open directory in write mode. If that directory has read-only access, creatfile() must return INVALID_HANDLE_VALUE otherwise handle value..
Can u give one example for that?
#include<windows.h>
#include<stdio.h>
#include<WCHAR.h>

int main()
{
WCHAR userPath[] = L"E:\\Demo"; /* Demo is read Only Folder*/
HANDLE hFile = NULL;

hFile = ::CreateFile(userPath,
GENERIC_WRITE ,
FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS,
NULL);

if(hFile == INVALID_HANDLE_VALUE)
{
wprintf(L"Error HANDLE = 0x%x \n",hFile);
}
else
{
wprintf(L"Suceess HANDLE = 0x%x \n",hFile);
::CloseHandle(hFile);
}

}


I done this sample program. This program is working. If anybody found flaws in this , plese let me know.
To open a directory you must specify FILE_FLAG_BACKUP_SEMANTICS flag to CreateFile(). To clear read-only flag, use SetFileAttributes().
Ok buddy,
Thanks for your reply..
Actually i have new problem. I want to use createfile for directory, where specific user has Deny prvelages.. So what should i do?
Topic archived. No new replies allowed.