zoukankan      html  css  js  c++  java
  • 获取目录下所有文件名

    c++

    
    #include <io.h>
    #include <fstream>
    #include <string>
    #include <vector>
    #include <iostream>
    using namespace std;
    
    // 得到路径path下的指定格式的 所有文件文件名
     void getJustCurrentFiles(string path, vector<string> & files)
     {
       //文件句柄
       long  hFile  =  0;
       //文件信息
       struct _finddata_t fileinfo;
       string p;
       if((hFile = _findfirst(p.assign(path).append("\*.txt").c_str(),&fileinfo)) != -1)
       {
         do
         {
           if((fileinfo.attrib & _A_SUBDIR)){  }
           else
           {
             files.push_back(fileinfo.name);
             // 完整路劲
             // files.push_back(p.assign(path).append("\").append(fileinfo.name) );
           }
         }while(_findnext(hFile, &fileinfo) == 0);
         _findclose(hFile);
       }
     }
    
     int main(int argc, char const *argv[])
     {
        std::vector<string> fs;
        getJustCurrentFiles("E:\",fs);
    
        for (std::vector<string>::iterator i = fs.begin(); i != fs.end(); ++i)
        {
            cout<<*i<<endl;
        }
         return 0;
     }
    
    

    python

    import os
    
    def getfilelist(path,file_form):
        f_list = os.listdir(path)
        for l in f_list[:]:
            if os.path.splitext(l)[1] == file_form :
                print l
        #print f_list
    
    if __name__ == '__main__':
        getfilelist('E:\','.txt')
    
    
  • 相关阅读:
    bs4的学习
    mysqldb模块的简单用法
    起点中文网(主要是在目录下创建文件)
    怎么把列表转化为字符串
    GUI开发者桌面搜索文件工具
    用表格形式保存文档 xlwt
    如何解决编码有问题
    影魔
    龙与地下城
    不等关系
  • 原文地址:https://www.cnblogs.com/iois/p/5371184.html
Copyright © 2011-2022 走看看