• <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
            <2012年4月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            常用鏈接

            留言簿(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 語言的庫的辦法:

            函數(shù)名: 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; 

            // 核查目錄,若目錄不存在,創(chuàng)建目錄
            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), "創(chuàng)建目錄[%s]失敗,請檢查權(quán)限", pszPath );
                    ::MessageBox( NULL, szDir, 
            "創(chuàng)建目錄失敗", 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 風輕云淡 閱讀(11086) 評論(0)  編輯 收藏 引用 所屬分類: C++
            国产无套内射久久久国产| 国产成人精品三上悠亚久久| 91久久婷婷国产综合精品青草| 亚洲精品乱码久久久久久| 蜜臀av性久久久久蜜臀aⅴ| 国产三级久久久精品麻豆三级| 国产精品久久波多野结衣| 99久久国产免费福利| 亚洲精品第一综合99久久| 精品国产乱码久久久久久郑州公司| 久久九九免费高清视频| 久久国产欧美日韩精品| 日韩欧美亚洲综合久久影院d3| 伊人久久大香线蕉AV一区二区| 久久夜色精品国产网站| 无码任你躁久久久久久老妇| 国产成人精品久久二区二区| 亚洲一区精品伊人久久伊人| 久久国产精品成人免费| 99久久免费国产精品特黄| 成人亚洲欧美久久久久| 色欲综合久久中文字幕网| 久久se这里只有精品| 粉嫩小泬无遮挡久久久久久| 亚洲精品乱码久久久久久不卡| 婷婷综合久久狠狠色99h| 亚洲午夜久久久影院| 午夜精品久久久内射近拍高清 | 久久久亚洲欧洲日产国码aⅴ| 品成人欧美大片久久国产欧美...| 色偷偷偷久久伊人大杳蕉| 亚洲国产成人精品女人久久久 | 狠狠色噜噜狠狠狠狠狠色综合久久| 无码精品久久一区二区三区| 国产精品VIDEOSSEX久久发布| 99久久婷婷免费国产综合精品| 色婷婷综合久久久久中文一区二区 | 国产精品久久久久天天影视| 无码日韩人妻精品久久蜜桃| 伊人久久大香线蕉AV色婷婷色| 一级女性全黄久久生活片免费|