zoukankan      html  css  js  c++  java
  • 转发—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>  
         
    

      

  • 相关阅读:
    文件的类型
    读取文件,并按原格式输出文件内容的三种方式
    react hook代码框架
    器具的行为模式
    设计模式
    cpu 内存 机器语言 汇编 高级语言 平台之间的关系
    操作系统之内存
    操作系统之文件
    操作系统之IO
    七层模型之应用层
  • 原文地址:https://www.cnblogs.com/1996313xjf/p/5907563.html
Copyright © 2011-2022 走看看