• <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++博客 :: 首頁 :: 聯系 :: 聚合  :: 管理
              140 Posts :: 1 Stories :: 11 Comments :: 0 Trackbacks

            常用鏈接

            留言簿(1)

            我參與的團隊

            搜索

            •  

            最新評論

            閱讀排行榜

            評論排行榜

            文章轉自:http://blogger.org.cn/blog/more.asp?name=hongrui&id=28011
            windows平臺下使用vc或gcc
            函數名: 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 指針類似,它是一個用于跟蹤目錄流的操作系統特定的對象。
            使用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函數:

            #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 ) );
                
            //判斷各級子目錄是否存在,不存在則需要創建

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

                    
            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 閱讀(3513) 評論(0)  編輯 收藏 引用
            国产精品亚洲综合专区片高清久久久| 久久国产色AV免费观看| 久久精品成人欧美大片| 久久午夜免费视频| 99久久精品国内| 伊人色综合久久天天网| 97久久综合精品久久久综合| 国产精品一区二区久久精品无码| 久久久精品国产| 国产99久久久国产精品~~牛 | 中文国产成人精品久久不卡 | 午夜精品久久久久成人| 无码伊人66久久大杳蕉网站谷歌| 99久久国产热无码精品免费久久久久| 中文成人久久久久影院免费观看| www.久久热.com| 日韩人妻无码一区二区三区久久| 国产精品嫩草影院久久| 国内精品久久久久伊人av| 婷婷国产天堂久久综合五月| 国产免费久久精品丫丫| 丰满少妇人妻久久久久久| 免费久久人人爽人人爽av| 久久99精品久久久久久齐齐| 99久久国产热无码精品免费| 77777亚洲午夜久久多喷| 久久中文字幕人妻熟av女| 久久无码一区二区三区少妇 | 久久成人精品视频| 亚洲精品无码久久久久去q | 天天综合久久久网| www.久久热.com| 99精品伊人久久久大香线蕉| 久久99精品国产99久久| 久久精品国产只有精品2020| 久久超乳爆乳中文字幕| 国内精品伊人久久久久av一坑| 久久99国产综合精品女同| 久久99国产乱子伦精品免费| 国产精品久久久久久一区二区三区| 久久婷婷激情综合色综合俺也去|