#include <Windows.h>
#include <tchar.h>
BOOL main(int argc, PTCHAR argv[])
{
DWORD dwAttrs = 0L;
DWORD dwErrCode = 0L;
BOOL bState = FALSE;
LPCTSTR lpPath = _T("Directory");
//Create directory ...
bState = CreateDirectory(lpPath, NULL);
if (!bState)
{
dwErrCode = GetLastError();
if (dwErrCode == ERROR_ALREADY_EXISTS)
{
_tprintf(_T("The directory is already exists./n"));
}
else if (dwErrCode == ERROR_PATH_NOT_FOUND)
{
_tprintf(_T("The Directory not found./n"));
return FALSE;
}
else
{
_tprintf(_T("Unknow Error Code:The ErrCode: %d. %d"), dwErrCode);
return FALSE;
}
}
// Get File Attrbutes...
dwAttrs = GetFileAttributes(lpPath);
if (dwAttrs == INVALID_FILE_ATTRIBUTES)
{
_tprintf(_T("Get File Attributes error.The ErrCode: %d."), GetLastError());
return FALSE;
}
else
{
// if not only read...
if (!(dwAttrs & FILE_ATTRIBUTE_READONLY))
{
// Set only read...
bState = SetFileAttributes(lpPath, (dwAttrs | FILE_ATTRIBUTE_HIDDEN));
if (!bState)
{
_tprintf(_T("Set File Attributes error./n"));
return FALSE;
}
}
}
_tprintf(_T("test file attributes ok!/n"));
return TRUE;
}