• <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>

            積木

            No sub title

              C++博客 :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            文章轉自:http://blogger.org.cn/blog/more.asp?name=hongrui&id=28011
            windows平臺下使用vc或gcc
            函數(shù)名: access
            功  能: 確定文件的訪問權限
            用  法: 
            int access(const char *filename, int amode); 文件的話還可以檢測讀寫權限,文件夾的話則只能判斷是否存在
            #include 
            "stdafx.h"
            #include  
            <io.h>
            #include  
            <stdio.h>
            #include  
            <stdlib.h>

            void main( void )
            {
               
            /* Check for exist */
               
            if( (_access( "C:\\windows"0 )) != -1 )
               {
                  printf( 
            "windows exists " );
                 
                  
               }
            }
            其實判斷文件存在fopen就行了。
            linux下或者gcc下
            #include 
            <stdio.h>
            #include 
            <stdlib.h>

            #include 
            <dirent.h>
            #include 
            <unistd.h>
            void main( void )
            {
             DIR 
            *dir = NULL;
                 
            /* Open the given directory, if you can. */  
                dir 
            = opendir( "C:\\windows" );
                 
            if( dir != NULL ) {
                     printf( 
            "Error opening " );
                     
            return ;
                 }
            }
            opendir() 返回的 DIR 指針與 fopen() 返回的 FILE 指針類似,它是一個用于跟蹤目錄流的操作系統(tǒng)特定的對象。
            使用c
            ++標準庫
            #include 
            "stdafx.h"
            #include 
            <iostream>
            #include 
            <fstream>
            using namespace std;
            #define FILENAME  "C:\\windows"
            int main()
            {
                 fstream file;
                 file.open(FILENAME,ios::
            in);
                 
            if(!file)
                 {
                     cout
            <<FILENAME<<"存在";
                  }
                  
            else
                  {
                      cout
            <<FILENAME<<"不存在";
                  }
                  
            return 0;
            }
            gcc編譯去掉#include 
            "stdafx.h"即可
            使用Windows API PathFileExists

            #include 
            "stdafx.h"
            #include 
            <iostream>
            #include 
            <windows.h>
            #include 
            <shlwapi.h>
            #pragma   comment(lib,
            "shlwapi.lib"
            using namespace std;
            #define FILENAME  "C:\\windows"
            int main()
            {
                  
            if (::PathFileExists(FILENAME))
                   cout
            <<"exist";
                
            return 0;
            }

            注意windows.h 一定要在shlwapi.h前面定義
            使用boost的filesystem類庫的exists函數(shù):

            #include 
            <boost/filesystem/operations.hpp>
            #include 
            <boost/filesystem/path.hpp>
            #include 
            <boost/filesystem/convenience.hpp>

            int GetFilePath(std::string &strFilePath)
            {
                
            string strPath;
                
            int nRes = 0;

                
            //指定路徑

                strPath 
            = "D:\myTest\Test1\Test2";
                
            namespace fs = boost::filesystem;

                
            //路徑的可移植

                fs::path full_path( fs::initial_path() );
                full_path 
            = fs::system_complete( fs::path(strPath, fs::native ) );
                
            //判斷各級子目錄是否存在,不存在則需要創(chuàng)建

                
            if ( !fs::exists( full_path ) )
                {
                    
            // 創(chuàng)建多層子目錄

                    
            bool bRet = fs::create_directories(full_path);
                    
            if (false == bRet)
                    {
                        
            return -1;
                    }

                }
                strFilePath 
            = full_path.native_directory_string();

                
            return 0;
            }


            posted on 2014-03-23 21:27 Jacc.Kim 閱讀(3502) 評論(0)  編輯 收藏 引用
            伊人色综合九久久天天蜜桃| 新狼窝色AV性久久久久久| 国产精品内射久久久久欢欢| 欧美性猛交xxxx免费看久久久| 久久永久免费人妻精品下载| 精品99久久aaa一级毛片| 久久久久久久亚洲Av无码| 精品久久久久久久国产潘金莲 | 久久精品国产亚洲网站| 久久99精品国产麻豆宅宅| 久久露脸国产精品| 久久久久无码中| 久久久91人妻无码精品蜜桃HD| 亚洲国产精品久久电影欧美 | 日本强好片久久久久久AAA| 国产精品欧美亚洲韩国日本久久| 久久亚洲国产精品成人AV秋霞| 精品久久久久久久中文字幕| 久久水蜜桃亚洲av无码精品麻豆 | 伊人久久大香线蕉精品不卡| 狠狠狠色丁香婷婷综合久久五月| 久久人与动人物a级毛片| 欧美午夜精品久久久久久浪潮| 日韩精品久久久久久| 国产精品99久久久久久董美香| 久久综合香蕉国产蜜臀AV| 色婷婷久久综合中文久久一本| 99久久亚洲综合精品成人| 久久精品成人免费观看97| 久久99精品国产99久久| 国产精品久久久久久福利漫画| 久久99国产综合精品女同| 欧美777精品久久久久网| 91精品国产乱码久久久久久| 久久久一本精品99久久精品88| 国产69精品久久久久久人妻精品| 久久99国产综合精品女同| 国产高潮国产高潮久久久| 无码人妻久久一区二区三区免费丨 | 久久精品成人欧美大片| 久久精品国产亚洲7777|