本文整理汇总了C++中GetFileAttributesA函数的典型用法代码示例。如果您正苦于以下问题:C++ GetFileAttributesA函数的具体用法?C++ GetFileAttributesA怎么用?C++ GetFileAttributesA使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetFileAttributesA函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: knh_exists
kbool_t knh_exists(CTX ctx, const char *fname)
{
kbool_t res = 0;
if(fname == NULL || fname[0] == 0) return 0;
#if defined(K_USING_WINDOWS_)
DWORD attr = GetFileAttributesA(fname);
res = (attr != -1);
#elif defined(K_USING_POSIX_)
struct stat buf;
res = (stat(fname, &buf) != -1);
#else
#endif
if(res == 0) {
DBG_P("'%s' NOTFOUND", fname);
}
return res;
}
示例2: FSExistDirectory
bool FSExistDirectory(const char *dirName)
{
#if defined(_WIN32_WCE)
return FSExistDirectory( UniString(dirName) );
#elif defined(WIN32)
if ( dirName == NULL ) return false;
if ( *dirName == 0 ) return false;
DWORD attr = GetFileAttributesA(dirName);
return ((attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY));
#else
UniString uniString(dirName);
return FSExistDirectory(uniString);
#endif
}
示例3: knh_path_isdir
knh_bool_t knh_path_isdir(CTX ctx, knh_path_t *ph)
{
const char *pname = P_text(ph) + ph->pbody;
if(pname[0] == 0) return 0;
#if defined(K_USING_WINDOWS)
DWORD attr = GetFileAttributesA(pname);
if(attr == -1) return 0;
return ((attr & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY);
#elif defined(K_USING_POSIX_)
struct stat buf;
if(stat(pname, &buf) == -1) return 0;
return S_ISDIR(buf.st_mode);
#else
// avoid "unused variable" warning unused variable
(void)phname;
return 0;
#endif
}
示例4: __win_fs_exist
/*
* __win_fs_exist --
* Return if the file exists.
*/
static int
__win_fs_exist(WT_FILE_SYSTEM *file_system,
WT_SESSION *wt_session, const char *name, bool *existp)
{
WT_DECL_RET;
WT_SESSION_IMPL *session;
WT_UNUSED(file_system);
session = (WT_SESSION_IMPL *)wt_session;
if (GetFileAttributesA(name) != INVALID_FILE_ATTRIBUTES)
*existp = true;
else
*existp = false;
return (0);
}
示例5: sqlite3WinFileExists
/*
** Return TRUE if the named file exists.
*/
int sqlite3WinFileExists(const char *zFilename){
int exists = 0;
void *zConverted = convertUtf8Filename(zFilename);
if( zConverted==0 ){
return SQLITE_NOMEM;
}
if( isNT() ){
exists = GetFileAttributesW((WCHAR*)zConverted) != 0xffffffff;
}else{
#if OS_WINCE
return SQLITE_NOMEM;
#else
exists = GetFileAttributesA((char*)zConverted) != 0xffffffff;
#endif
}
sqliteFree(zConverted);
return exists;
}
示例6: __declspec
extern "C" __declspec(dllexport) bool ApplyPatchSuspended(HANDLE hProcess, DWORD)
{
// Get target file name
char szTarget[MAX_PATH];
strncpy(szTarget, GetBWAPITarget().c_str(), MAX_PATH-1);
szTarget[MAX_PATH-1] = '\0';
// Check if the file exists, INVALID_FILE_ATTRIBUTES will have this bit set too
if ( GetFileAttributesA(GetBWAPITarget().c_str()) & FILE_ATTRIBUTE_DIRECTORY )
return BWAPIError("Unable to find %s.", szTarget);
// Get the address for the LoadLibrary procedure
HMODULE hKernalModule = GetModuleHandle(L"Kernel32");
if ( !hKernalModule )
return BWAPIError("Unable to get module handle for Kernel32.");
LPTHREAD_START_ROUTINE loadLibAddress = (LPTHREAD_START_ROUTINE)GetProcAddress(hKernalModule, "LoadLibraryA" );
if ( !loadLibAddress )
return BWAPIError("Could not get Proc Address for LoadLibraryA.");
// Create a remote allocation
VAlloc alloc(hProcess, MAX_PATH);
if ( !alloc )
return BWAPIError("Could not allocate memory for DLL path.");
// Write the DLL path to the allocation
if ( !alloc.Write(szTarget, MAX_PATH) )
return BWAPIError("Write process memory failed.");
// Create a remote thread for LoadLibrary and pass the DLL path as a parameter
RemoteThread thread(hProcess, loadLibAddress, alloc.GetAddress());
if ( !thread )
return BWAPIError("Unable to create remote thread.");
// Wait for the thread to finish
if ( !thread.Wait() )
return BWAPIError("WaitForSingleObject failed.");
// The exit code for LoadLibrary is its return value, if it's NULL then loading failed
if ( thread.GetExitCode() == NULL )
return BWAPIError("Injection failed.\nThis is caused when BWAPI crashes before injecting completely.");
return true; //everything OK
}
示例7: CheckFileExistsInProgramGroups
/* Check for Existence (or non-existence) of a file or group
* When testing for existence of a group, groupName is not needed
*/
static void CheckFileExistsInProgramGroups(const char *nameToCheck, BOOL shouldExist, BOOL isGroup,
const char *groupName, int testParams)
{
char path[MAX_PATH];
DWORD attributes;
int len;
lstrcpyA(path, ProgramsDir);
len = strlen(path) + strlen(nameToCheck)+1;
if (groupName != NULL)
{
len += strlen(groupName)+1;
}
ok (len <= MAX_PATH, "Path Too Long.%s\n", GetStringFromTestParams(testParams));
if (len <= MAX_PATH)
{
if (groupName != NULL)
{
strcat(path, "\\");
strcat(path, groupName);
}
strcat(path, "\\");
strcat(path, nameToCheck);
attributes = GetFileAttributesA(path);
if (!shouldExist)
{
ok (attributes == INVALID_FILE_ATTRIBUTES , "File exists and shouldn't %s.%s\n",
path, GetStringFromTestParams(testParams));
} else {
if (attributes == INVALID_FILE_ATTRIBUTES)
{
ok (FALSE, "Created File %s doesn't exist.%s\n", path, GetStringFromTestParams(testParams));
} else if (isGroup) {
ok (attributes & FILE_ATTRIBUTE_DIRECTORY, "%s is not a folder (attr=%x).%s\n",
path, attributes, GetStringFromTestParams(testParams));
} else {
ok (attributes & FILE_ATTRIBUTE_ARCHIVE, "Created File %s has wrong attributes (%x).%s\n",
path, attributes, GetStringFromTestParams(testParams));
}
}
}
}
示例8: FSExistFile
bool FSExistFile(const char *fileName)
{
#if defined(_WIN32_WCE)
return (GetFileAttributes(UniString(fileName)) != INVALID_FILE_ATTRIBUTES);
#elif defined(WIN32)
if ( fileName == NULL ) return false;
if ( *fileName == 0 ) return false;
// return PathFileExistsA(fileName);
return (GetFileAttributesA(fileName) != INVALID_FILE_ATTRIBUTES);
// return _access(fileName, 0) == 0;
#else
UniString uniString(fileName);
return FSExistFile(uniString);
#endif
}
示例9: PDLASSERT
BOOL PDLAPI LFile::Exists(
__in PCSTR lpszFileName,
__in BOOL bIncludeDir)
{
PDLASSERT(NULL != lpszFileName);
#ifndef _WIN32_WCE
DWORD dwAttr = GetFileAttributesA(lpszFileName);
if (INVALID_FILE_ATTRIBUTES == dwAttr)
return FALSE;
if (bIncludeDir)
return TRUE;
else
return 0 == (FILE_ATTRIBUTE_DIRECTORY & dwAttr);
#else
LStringW str = lpszFileName;
return Exists(str);
#endif // _WIN32_WCE
}
示例10: fileExists
////////////////////////////////////////////////////////////////////////////////////
///
/// \param filename The file to check for.
///
/// \return True 1 if the file exists, otherwise 0.
///
////////////////////////////////////////////////////////////////////////////////////
int FileIO::fileExists(const char * filename)
{
int result = false;
#ifdef WIN32
if (GetFileAttributesA(filename) != /*INVALID_FILE_ATTRIBUTES*/ -1)
{
result = true;
}
#else
FILE * file = fopen(filename, "rb");
if (file)
{
fclose(file);
result = true;
}
#endif
return result;
}
示例11: GetFileAttributesA
//------------------------------------------//
// FileHelper::CheckFolderExists
//------------------------------------------//
bool FileHelper::CheckFolderExists(const std::string& pDirectory)
{
//http://stackoverflow.com/questions/8233842/how-to-check-if-directory-exist-using-c-and-winapi
#if __WINDOWS__
DWORD ftyp = GetFileAttributesA(pDirectory.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
{
return false; //something is wrong with your path!
}
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
{
return true; // this is a directory!
}
#endif
return false;
}
示例12: dirExists
bool dirExists(const std::string& dirName)
{
#ifdef _WIN32
DWORD ftyp = GetFileAttributesA(dirName.c_str());
if (ftyp == INVALID_FILE_ATTRIBUTES)
return false; //something is wrong with your path!
if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
return true; // this is a directory!
#else
struct stat sb;
if (stat(dirName.c_str(), &sb)==0 && S_ISDIR(sb.st_mode))
{
return true;
}
#endif
return false;
}
示例13: mpqapi_set_hidden
bool __fastcall mpqapi_set_hidden(char *pszArchive, bool hidden)
{
char *v2; // edi
BOOL v3; // esi
DWORD v4; // eax
bool result; // al
DWORD v6; // esi
v2 = pszArchive;
v3 = hidden;
v4 = GetFileAttributesA(pszArchive);
if ( v4 == -1 )
return GetLastError() == ERROR_FILE_NOT_FOUND;
v6 = v3 != 0 ? FILE_ATTRIBUTE_SYSTEM|FILE_ATTRIBUTE_HIDDEN : 0;
if ( v4 == v6 )
result = 1;
else
result = SetFileAttributesA(v2, v6);
return result;
}
示例14: GetFileAttr
uint GetFileAttr(const char *Name,const wchar *NameW)
{
#ifdef _WIN_ALL
if (WinNT() && NameW!=NULL && *NameW!=0)
return(GetFileAttributesW(NameW));
else
return(GetFileAttributesA(Name));
#elif defined(_DJGPP)
return(_chmod(Name,0));
#else
struct stat st;
if (stat(Name,&st)!=0)
return(0);
#ifdef _EMX
return(st.st_attr);
#else
return(st.st_mode);
#endif
#endif
}
示例15: af_IsFileExist
// Check if a specified file exist
bool af_IsFileExist(const char * szRelativePath)
{
// we must supply a relative path to GetFilePck function
AFilePackage * pPackage = g_AFilePackMan.GetFilePck(szRelativePath);
if( pPackage )
{
// Get file entry
AFilePackage::FILEENTRY FileEntry;
int iEntryIndex;
if (pPackage->GetFileEntry(szRelativePath, &FileEntry, &iEntryIndex))
return true;
}
{ // not found in package, so test if exist on the disk, here we must use full path
char szFullPath[1024];
sprintf(szFullPath, "%s/%s", g_szBaseDir, szRelativePath);
#ifdef _WIN32
if( INVALID_FILE_ATTRIBUTES != GetFileAttributesA(szFullPath) )
return true;
#else
if (access(szFullPath, 0) == 0)
return true;
#endif
}
//try backup packages
{
AFilePackage * pPackage = g_AFilePackMan.GetFilePck(szRelativePath, true);
if( pPackage )
{
// Get file entry
AFilePackage::FILEENTRY FileEntry;
int iEntryIndex;
if (pPackage->GetFileEntry(szRelativePath, &FileEntry, &iEntryIndex))
return true;
}
}
return false;
}