• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 132  文章 - 51  trackbacks - 0
            <2014年3月>
            2324252627281
            2345678
            9101112131415
            16171819202122
            23242526272829
            303112345

            常用鏈接

            留言簿(7)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            cocos2d-x

            OGRE

            OPenGL

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            C/C++判斷一個文件是否存在
            1.
            bool isExistFile(const char *pszFileName){
                FILE 
            *fp = fopen(pszFileName, "rb");
                
            if(fp == NULL)
                    
            return false;
                fclose(fp);
                
            return true;
            }

            bool isExistFile(const char *pszFileName){
                    fstream file;
                    file.open(pszFileName,ios::
            in);
                    
            if(!file)
                        
            return false;

                    
            return true;
                }

            2.利用 c 語言的庫的辦法:

            函數名: access

            // crt_access.c
            #include  <io.h>
            #include  
            <stdio.h>
            #include  
            <stdlib.h>

            int main( void )
            {
               
            /* Check for existence */
               
            if( (_access( "crt_ACCESS.C"0 )) != -1 )
               
            {
                  printf( 
            "File crt_ACCESS.C exists\n" );
                  
            /* Check for write permission */
                  
            /* assume file is read-only */
                  
            if( (_access( "crt_ACCESS.C"2 )) == -1 )
                     printf( 
            "File crt_ACCESS.C does not have write permission\n" );
               }

            }

            3.用FindFirstFile


            #include <windows.h>
            #include 
            <string> 
            #include 
            <vector>
            using namespace std; 

            // 核查目錄,若目錄不存在,創建目錄
            bool FindOrCreateDirectory( const char* pszPath )
            {
                WIN32_FIND_DATA fd;
                HANDLE hFind 
            = ::FindFirstFile( pszPath, &fd );
                
            while( hFind != INVALID_HANDLE_VALUE )
                
            {
                    
            if ( fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
                        
            return true;
                }


                
            if ( !::CreateDirectory( pszPath, NULL ) )
                
            {
                    
            char szDir[MAX_PATH];
                    sprintf_s( szDir, 
            sizeof(szDir), "創建目錄[%s]失敗,請檢查權限", pszPath );
                    ::MessageBox( NULL, szDir, 
            "創建目錄失敗", MB_OK|MB_ICONERROR );
                    
            return false;
                }


                
            return true;
            }


            // 遍歷目錄
            bool CheckDirectory( char* pszPath )
            {
                vector
            < std::string > vtPath;

                
            const char* sep = "\\/";
                
            char* next_token;
                
            char* token =  strtok_s( pszPath, sep, &next_token);
                
            while( token != NULL )
                
            {
                    vtPath.push_back( token );
                    token 
            = strtok_s(NULL, sep, &next_token);
                }


                
            if ( vtPath.size() > 0 )
                
            {
                    
            if ( vtPath[0== "." )
                        vtPath.erase( vtPath.begin() );
                }


                
            // 核查所有路徑是否存在
                std::string strCurPath;
                
            for( size_t i = 0; i  < (int)vtPath.size(); ++i )
                
            {
                    strCurPath 
            += vtPath[i];
                    strCurPath 
            += '\\';

                    
            if ( !FindOrCreateDirectory( strCurPath.c_str() ) )
                    
            {
                        
            return false;
                    }

                }


                
            return true;
            }



            int main() 

                
            char szPath[MAX_PATH] = "./main\\test\\hello/jump\\test\\";
                CheckDirectory( szPath );
                

                system(
            "pause");
                
            return 0
            }
             
            posted on 2012-03-24 15:12 風輕云淡 閱讀(11054) 評論(0)  編輯 收藏 引用 所屬分類: C++
            久久人妻少妇嫩草AV无码蜜桃| 色综合久久中文字幕综合网| 一级做a爰片久久毛片毛片| 国产精品九九久久精品女同亚洲欧美日韩综合区 | 久久国产乱子伦精品免费午夜| 久久久无码精品亚洲日韩按摩| 亚洲熟妇无码另类久久久| 亚洲精品乱码久久久久久自慰| 久久99久久99精品免视看动漫| 99久久国产宗和精品1上映 | 成人精品一区二区久久久| 国产精品美女久久久网AV| 亚洲国产精久久久久久久| 久久精品国产亚洲5555| 一本大道久久香蕉成人网| 狠狠精品久久久无码中文字幕| 99久久国产宗和精品1上映| 精品久久久久久无码专区不卡| 高清免费久久午夜精品| 国产69精品久久久久9999| 久久久精品国产亚洲成人满18免费网站 | 无码人妻久久一区二区三区免费丨 | 久久久亚洲裙底偷窥综合| 亚洲精品无码久久久久久| 久久国产精品久久国产精品| 狠狠精品干练久久久无码中文字幕 | 成人亚洲欧美久久久久 | 久久人妻无码中文字幕| 性做久久久久久久| 国产三级精品久久| 久久精品国产精品亚洲精品| 精品免费tv久久久久久久| 亚洲国产成人久久综合区| 久久国产欧美日韩精品| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久精品夜夜夜夜夜久久| 精品久久久久久国产免费了| 久久国产劲爆AV内射—百度| 国产 亚洲 欧美 另类 久久| 午夜天堂精品久久久久| 久久久无码精品午夜|