• <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
            <2025年6月>
            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 語言的庫的辦法:

            函數名: 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 風輕云淡 閱讀(11086) 評論(0)  編輯 收藏 引用 所屬分類: C++
            亚洲中文久久精品无码ww16| MM131亚洲国产美女久久| 中文字幕久久欲求不满| 国产69精品久久久久9999| 久久黄视频| 亚洲精品无码久久久久去q| 国产精品久久自在自线观看| 99久久精品国产一区二区三区 | 久久成人18免费网站| 日韩影院久久| 99久久婷婷国产一区二区| 污污内射久久一区二区欧美日韩| 无码精品久久久天天影视| 久久99久久成人免费播放| 欧洲人妻丰满av无码久久不卡| 亚洲国产精品久久久久婷婷老年| 久久久久久精品无码人妻| 精品久久久久国产免费| 国产精品美女久久久久网| 伊人久久久AV老熟妇色| 日韩美女18网站久久精品 | 精品久久一区二区三区| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久精品成人免费网站| 狠狠色丁香久久婷婷综合_中| 久久午夜电影网| 91精品国产综合久久婷婷| 久久天天躁狠狠躁夜夜躁2014| 免费观看成人久久网免费观看| 精品国产一区二区三区久久久狼 | 亚洲综合久久综合激情久久| 无码伊人66久久大杳蕉网站谷歌 | 久久精品国产亚洲AV蜜臀色欲| 久久精品这里只有精99品| 国产精品亚洲综合专区片高清久久久 | 亚洲精品高清一二区久久| 久久国产精品偷99| 久久久久亚洲精品无码网址| 久久五月精品中文字幕| 国产99久久久国产精品小说| 亚洲欧洲中文日韩久久AV乱码|