當前位置: 首頁>>代碼示例>>C++>>正文


C++ GetFileAttributesA函數代碼示例

本文整理匯總了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;
}
開發者ID:imasahiro,項目名稱:konohascript,代碼行數:17,代碼來源:os.c

示例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
}
開發者ID:kjoon010,項目名稱:IncubeTech-Contribs,代碼行數:17,代碼來源:FileSystem.cpp

示例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
}
開發者ID:shinpei,項目名稱:konoha-wand,代碼行數:18,代碼來源:os.c

示例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);
}
開發者ID:GYGit,項目名稱:mongo,代碼行數:22,代碼來源:os_fs.c

示例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;
}
開發者ID:bazhenovc,項目名稱:nebula3,代碼行數:21,代碼來源:os_win.c

示例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
}
開發者ID:dansgithubuser,項目名稱:ninepool,代碼行數:44,代碼來源:chaoslauncher.cpp

示例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));
            }
        }
    }
}
開發者ID:AmesianX,項目名稱:wine,代碼行數:46,代碼來源:progman_dde.c

示例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
}
開發者ID:kjoon010,項目名稱:IncubeTech-Contribs,代碼行數:19,代碼來源:FileSystem.cpp

示例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
}
開發者ID:lvtx,項目名稱:pdl-titilima,代碼行數:19,代碼來源:file.cpp

示例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;
}
開發者ID:rwoodley,項目名稱:FaceToys,代碼行數:27,代碼來源:fileio.cpp

示例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;
}
開發者ID:TaintedGear,項目名稱:GameFramework,代碼行數:23,代碼來源:FileHelper.cpp

示例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;
}
開發者ID:Constellation,項目名稱:doxygen,代碼行數:20,代碼來源:doxysearch.cpp

示例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;
}
開發者ID:Alim-Oezdemir,項目名稱:devilution,代碼行數:20,代碼來源:mpqapi.cpp

示例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
}
開發者ID:ajnelson,項目名稱:bulk_extractor,代碼行數:20,代碼來源:filefn.cpp

示例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;
}
開發者ID:fengqk,項目名稱:Art,代碼行數:42,代碼來源:AFI.cpp


注:本文中的GetFileAttributesA函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。