• 转发—c++实现查找文件夹下的文件


    [cpp] view plain copy 在CODE上查看代码片派生到我的代码片
    开始以为是个很简单问题后来才发现有点麻烦,最后实现如下,其中tmp是要查找的文件的类型,改成其他的如.java就可以查找java类型文件名  
    [cpp] view plain copy 在CODE上查看代码片派生到我的代码片
    <pre code_snippet_id="266604" snippet_file_name="blog_20140331_2_3829526" name="code" class="cpp">#include<iostream>  
    #include<dirent.h>  
    using namespace std;  
    int main( void )  
    {  
        DIR* dirp;  
        struct dirent* direntp;  
        dirp = opendir( "F:\output\codegen" );  
        string tmp =".txt";  
        string filename;  
        if( dirp != NULL )   
        {  
            for(;;) {  
                direntp = readdir( dirp );  
                if( direntp == NULL )   
            break;  
                string s = direntp->d_name;  
                int x = s.find(tmp,0);             
                if(x>0){  
                    string last;  
            last.assign(s,0,x);  
            filename=last;  
            //filename 就是txt文件的名称,不包含txt后缀,得到名称后添加.txt后缀就可以直接打开进行其他操作  
                }  
            }  
            closedir( dirp );  
        }  
        cout<<filename<<endl;  
        return 0;  
    }</pre><br>  
    <br>  
    <pre></pre>  
    <pre></pre>  
         
    

      

  • 相关阅读:
    搜索算法总结
    浅谈cocosd之autorelease etain elease的理解
    lua和C++的交互(1)
    Unity相对于Cocos2d-x的比较
    Lua弱表Weak table
    socket编程学习step2
    ppt述职摘要
    LuaJavaBridge
    鱼书学习小结(一)
    网络协议HTTP TCP/UDP 浏览器缓存 Restful(十)
  • 原文地址:https://www.cnblogs.com/1996313xjf/p/5907563.html
Copyright © 2020-2023  润新知