国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
VC判斷文件目錄是否存在的眾多方法 - 含笑的日志 - 網(wǎng)易博客
 

1. 使用_access函數(shù),函數(shù)原型為 int _access( const char *path, int mode );
2. 使用CreateFile函數(shù),函數(shù)原型為: HANDLE CreateFile( LPCTSTR lpFileName, // pointer to name of the file DWORD dwDesiredAccess, // access (read-write) mode DWORD dwShareMode, // share mode LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security attributes DWORD dwCreationDisposition, // how to create DWORD dwFlagsAndAttributes, // file attributes HANDLE hTemplateFile // handle to file with attributes to // copy ); 
3. 使用FindFirstFile函數(shù),函數(shù)原型為: HANDLE FindFirstFile( LPCTSTR lpFileName, // pointer to name of file to search for LPWIN32_FIND_DATA lpFindFileData // pointer to returned information );
//例子:

BOOL CPubFunc::DirectoryExist(CString Path)
{
 WIN32_FIND_DATA fd;
 BOOL ret = FALSE;
    HANDLE hFind = FindFirstFile(Path, &fd);
    if ((hFind != INVALID_HANDLE_VALUE) && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
    {  //目錄存在
            ret = TRUE;    
    }
   FindClose(hFind);
 return ret;
}
 4. 使用GetFileAttributes函數(shù),函數(shù)原型如下: DWORD GetFileAttributes( LPCTSTR lpFileName // pointer to the name of a file or directory );
5. 使用Shell Lightweight Utility APIs函數(shù) PathFileExists()專門判斷文件和目錄時否存在的函數(shù)文件名可讀性比較強還可以判斷目錄是否存在 Header: Declared in Shlwapi.h Import Library: Shlwapi.lib 以上的各種方法供參考,函數(shù)具體用法需參見MSDN。
//這是MSDN中的例子:
#include <windows.h>
#include <iostream.h>
#include "Shlwapi.h"

void main( void )
{
// Valid file path name (file is there).
char buffer_1[] = "C:\\TEST\\file.txt"; 
char *lpStr1;
lpStr1 = buffer_1;
// Invalid file path name (file is not there).
char buffer_2[] = "C:\\TEST\\file.doc"; 
char *lpStr2;
lpStr2 = buffer_2;
// Return value from "PathFileExists". 
int retval; 
// Search for the presence of a file with a true result.
retval = PathFileExists(lpStr1);
if(retval == 1)
{
cout << "Search for the file path of : " << lpStr1 << endl;
cout << "The file requested \"" << lpStr1 << "\" is a valid file" << endl;
cout << "The return from function is : " << retval << endl;
}
else{
cout << "\nThe file requested " << lpStr1 << " is not a valid file" << endl;
cout << "The return from function is : " << retval << endl;
}
// Search for the presence of a file with a false result.
retval = PathFileExists(lpStr2);
if(retval == 1)
{
cout << "\nThe file requested " << lpStr2 << "is a valid file" << endl;
cout << "Search for the file path of : " << lpStr2 << endl;
cout << "The return from function is : " << retval << endl;
}
else{
cout << "\nThe file requested \"" << lpStr2 << "\" is not a valid file" << endl;
cout << "The return from function is : " << retval << endl;
}


6.使用CFileFind 類....這是一個InternetServices類,在此可以借用一下。也可以用于遍歷文件夾(s可指定深度)
BOOL CPubFunc::FileExist(CString FileName)
{
 CFileFind fFind;
 return fFind.FindFile(FileName); 
}

//創(chuàng)建目錄
 #include <winbase.h>
BOOL CreateDirectory(
  LPCTSTR
 lpPathName,                         // pointer to directory path string
  LPSECURITY_ATTRIBUTES lpSecurityAttributes  // pointer to security descriptor
);

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C++內(nèi)存管理
C++拷貝構(gòu)造函數(shù)
c/c++傳統(tǒng)兩種異常錯誤處理機制
【精華】vector用法精講
指針常量和常量指針
一般函數(shù)指針和類的成員函數(shù)指針
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服