Windows:

#include<iostream>
#include<string>
#include <io.h>
void readFileNameInDir(IN string strDir, INOUT vector<string>& vFileFullPath)
{
       long handle;    //文件句柄
       struct _finddata_t fileInfo;    //文件结构体
       handle = _findfirst(strDir.c_str(), &fileInfo);    //第一次查找,获取文件句柄
       while (!_findnext(handle, &fileInfo))
       {
              vFileFullPath.push_back(fileInfo.name)
       }
       _findclose(handle);
}    //readFileNameInDir()

Linux:

#include <string>
#include <vector>
#include <dirent.h>

void readFileNameInDir(IN string strDir, INOUT vector<string>& vFileFullPath)
{
       struct dirent* pDirent;
       DIR* pDir = opendir(strDir.c_str());
       if (pDir != NULL)
       {
              while ((pDirent = readdir(pDir)) != NULL)
              {
                     string strFileName = pDirent->d_name;
                     string strFileFullPath = strDir + "/" + strFileName;
                     vFileFullPath.push_back(strFileFullPath);
              }
              vFileFullPath.erase(vFileFullPath.begin(), vFileFullPath.begin() +  2);    //前两个存储的是当前路径和上一级路径,所以要删除
       }
}    //readFileNameInDir()

C++ 读取一个文件下所有文件的文件名的更多相关文章

  1. PHP读取一个目录下的文件个数

    <?php function FileCount($dir){ global $count; if(is_dir($dir)&&file_exists($dir)){ $ob=s ...

  2. 【转】忙里偷闲写的小例子---读取android根目录下的文件或文件夹

    原文网址:http://www.cnblogs.com/wenjiang/p/3140055.html 最近几天真的是各种意义上的忙,忙着考试,还要忙着课程设计,手上又有外包的项目,另一边学校的项目还 ...

  3. 忙里偷闲写的小例子---读取android根目录下的文件或文件夹

    最近几天真的是各种意义上的忙,忙着考试,还要忙着课程设计,手上又有外包的项目,另一边学校的项目还要搞,自己的东西还在文档阶段,真的是让人想死啊!! 近半个月来,C#这方面的编码比较多,android和 ...

  4. SpringBoot读取资源目录下的文件

    需要读取resources目录下的文件,那么方法如下: 假设在资源目录下的template目录下有一个文件a.txt,获取到文件流的方式 InputStream stream = this.getCl ...

  5. iOS案例:读取指定目录下的文件列表

    // // main.m // 读取指定目录下的文件列表 // // Created by Apple on 15/11/24. // Copyright © 2015年 Apple. All rig ...

  6. 【转】读取android根目录下的文件或文件夹

    原文网址:http://my.oschina.net/Ccx371161810/blog/287823 读取android根目录下的文件或文件夹 SDK的操作 读取android根目录下的文件或文件夹 ...

  7. Python 读取某个目录下的文件

    读取某个目录下的文件,如'/Users/test/test_kmls'目录下有test1.txt.test2.txt. 第一种方法读出的all_files是test1.txt.test2.txt im ...

  8. 如何用DOS命令,获取一个目录下的文件数目

    发信人: GOOGOODALLS (我爱Figo), 信区: DOS 标  题: 如何用DOS命令,获取一个目录下的文件数目? 发信站: 水木社区 (Fri Mar  9 08:40:01 2007) ...

  9. Python读取一个目录下的所有文件

    #!/usr/bin/python # -*- coding:utf8 -*- import os allFileNum = 0 def printPath(level, path): global ...

  10. python 读取一个目录下的所有目录和文件

    #!/usr/bin/python # -*- coding:utf8 -*- import os allFileNum = 0 def printPath(level, path): global ...

随机推荐

  1. arduino adc数模放大器

    http://ardui.co/archives/833 http://henrysbench.capnfatz.com/henrys-bench/arduino-voltage-measuremen ...

  2. 1129. Shortest Path with Alternating Colors

    原题链接在这里:https://leetcode.com/problems/shortest-path-with-alternating-colors/ 题目: Consider a directed ...

  3. file 的类型 input

    上传你选择的文件和相关信息.在 HTML 文档中 <input type="file"> 标签每出现一次,一个 FileUpload 对象就会被创建.该元素包含一个文本 ...

  4. BZOJ 3166: [Heoi2013]Alo 链表+可持久化trie

    链表这个东西非常好用啊 ~ code: #include <bits/stdc++.h> #define N 50010 #define inf 2000400000 #define se ...

  5. tbls ci 友好的数据库文档化工具

    tbls 是用golang 编写的数据库文档化工具,当前支持的数据库有pg.mysql.bigquery 此工具同时提供了变更对比.lint 校验,生成是markdown格式的 简单使用 安装 mac ...

  6. 洛谷 P2850 [USACO06DEC]虫洞Wormholes 题解

    P2850 [USACO06DEC]虫洞Wormholes 题目描述 While exploring his many farms, Farmer John has discovered a numb ...

  7. GoCN每日新闻(2019-10-07)

    GoCN每日新闻(2019-10-07) 国庆专辑:GopherChina 祝大家国庆节快乐(假期最后一天)   GoCN每日新闻(2019-10-07)   1. Go 不好的点:JSON 解析的探 ...

  8. Swarm容器集群管理(超详细)

    一.Swarm介绍 Swarm是Docker公司自研发的容器集群管理系统, Swarm在早期是作为一个独立服务存在, 在Docker Engine v1.12中集成了Swarm的集群管理和编排功能.可 ...

  9. [C++] new和delete运算符使用方法

    new 和 delete 是C++语言中的两个运算符,配套使用. new:用于分配内存,与C语言中的 malloc 相同,分配在堆内存 delete:用于释放内存,与C语言中的 free 相同,释放堆 ...

  10. MYSQL 什么时候用单列索引?什么使用用联合索引?

    我一个表 students 表,有3个字段 ,id,name,age 我要查询 通过 name 和age,在这两个字段 是创建 联合索引?还是分别在name和age上创建 单列索引呢? 多个字段查询什 ...