当前位置: 首页>>代码示例>>C++>>正文


C++ FileSystem::existDirectory方法代码示例

本文整理汇总了C++中FileSystem::existDirectory方法的典型用法代码示例。如果您正苦于以下问题:C++ FileSystem::existDirectory方法的具体用法?C++ FileSystem::existDirectory怎么用?C++ FileSystem::existDirectory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileSystem的用法示例。


在下文中一共展示了FileSystem::existDirectory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: exe

bool CommandPut::exe(FileSystem& fs, string parameter)
{
    istringstream input(parameter);
	string tfsPath;
    string localPath;
    int blocksize = -1; // add by fk
    input >> localPath >> tfsPath >>blocksize;  //get the parameters
    if (blocksize == -1) blocksize = 1;
   
    /**
     * if the path is null, it puts nothing 
     */
    if(tfsPath == "" && localPath == ""){
        cout << "USAGE: put <local_file> [<tfs_file>]" << endl;
        cout << "EXAMPLE: put filename1" << endl;
        cout << "         put filename1 ." << endl;
        cout << "         put filename1 ./filename2" << endl;
        cout << "         put /home/abc/filename1" << endl;
        cout << "         put /home/abc/filename1 ./filename2" << endl;
        return false;
    }
    // check local file
    struct stat fileStat;
    if (stat(localPath.c_str(), &fileStat) != 0){
        cout << "Error: put: no such file " << localPath << endl;
        return false;
    }
    bool bAbsolutePath;
    string localDir;
    string localFilename;
    FilePath::split(localPath, bAbsolutePath, localDir, localFilename);

    string tfsDir;
    string tfsFilename;
    FilePath::split(tfsPath, bAbsolutePath, tfsDir, tfsFilename);
    if (!bAbsolutePath){            // reletive path
        FilePath pathGenerator;
        tfsDir = pathGenerator.getPath(m_currentDir, tfsDir);
        tfsDir = pathGenerator.change(tfsDir); //change into absolutely path
        if(tfsDir != "/"){
            tfsDir +=  "/";
        }
    }
    if (tfsFilename.empty()){
        tfsFilename = localFilename;
    }
    tfsPath = tfsDir + tfsFilename;
    
    cout << "put " << localPath << " " << tfsPath << endl;
    
    try{
        if( !fs.existDirectory(tfsDir) ){
            cout << "Error: no such directory " << tfsDir << endl;
            return false;
        }

        //if the file is exist , the local file will be appended
        if( !fs.existFile(tfsPath) ){
            int chunkSize = (fileStat.st_size > MAX_CHUNK_SIZE) ? MAX_CHUNK_SIZE:DEFAULT_CHUNK_SIZE;
            chunkSize = chunkSize - chunkSize % blocksize;
            fs.createFile(tfsPath, 2 , chunkSize);
        }

        AppendStream tfsAppend;
        int bufferSize = (fileStat.st_size < MAX_BUFFER_SIZE) ? MAX_BUFFER_SIZE:DEFAULT_BUFFER_SIZE;
        tfsAppend.open(tfsPath, bufferSize);

        ifstream fin(localPath.c_str() , ios::binary);
        if(!fin){
            cout << "ERROR: put: open file " << localPath << endl;
            return false;
        }

        size_t MAXGET = 1024 * 1024 / blocksize * blocksize;
        if (MAXGET == 0) throw (TFSException("Block Size Exceed 1 M"));
        char *buffer = new char[MAXGET];

        while(fin){
            fin.read(buffer, MAXGET);
            //cout << "read " << fin.gcount() << endl;
            tfsAppend.append(buffer, fin.gcount());
        }
    }
    catch(TFSException& ex){
        cout << "ERROR: put: Get exception: " << ex.what() << endl;
        return false;
    }

    return true;
}
开发者ID:kyhhdm,项目名称:TPlatform,代码行数:90,代码来源:CommandPut.cpp


注:本文中的FileSystem::existDirectory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。