|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
" b9 \4 R1 ?$ u[mw_shl_code=cpp,true]#include <string>
- Z5 J8 P% }0 u4 u9 v8 K: f#include <io.h>" F$ }5 X" A6 w. S$ z$ C+ I
#include <vector>4 s* [3 H. o/ O
#include <iostream>1 M% f# D3 b" O0 T/ ^' Q2 l: z
#include <fstream>1 R# V- a* q, N4 p! Y* W, `
using namespace std;; }% ^4 w" Q3 ?3 Z4 L1 }
# R$ P/ h$ V& R/ g6 _: m- g0 g
+ T3 b% M1 I ?) q" h/************************************************************************/. @) f' z0 H+ c6 q
/* 获取文件夹下所有文件名
! e6 E; T$ j6 t 输入: * A' M# f; J" w1 ^+ C& [
path : 文件夹路径) D) Y1 c L8 J
exd : 所要获取的文件名后缀,如jpg、png等;如果希望获取所有
" T( e; e4 h8 y6 ` 文件名, exd = ".jt"
! X! @* n! l+ J- j. n' q 输出:! e4 J4 y2 K: d/ |* ~# H4 F+ e
files : 获取的文件名列表 含有路径: Y" x1 H; i# F) n" x2 v3 o
*/
+ ^, [2 Z! q: K/************************************************************************/
5 o3 ?& o) s( Z, T0 X0 Y' _) }- ]4 l
void CONFIG_getFiles( string path, string exd, vector<string>& files )
2 s9 ^' X5 @9 v7 f+ o" S{
! P4 c0 M; j1 n! a3 ]9 e$ y- ~ //文件句柄) Y. M, a7 b2 I
long hFile = 0;
$ j3 ?* ?, d% u! A' {: o //文件信息& z2 t6 ]5 q z/ A. V
struct _finddata_t fileinfo;
5 O) j: i" @) N string pathName, exdName;& v5 k) Q! } \5 q& q
L0 m" i. Y2 y' ?$ U
string p;
. a: z; t- x% l$ b t3 _ if((hFile = _findfirst(pathName.assign(path).append("\\*").c_str(),&fileinfo)) != -1)0 Y6 G1 Y" Y* j7 Y( ^0 \
{0 K4 x5 |4 ~# Q' D
do
* v" S7 }: @9 R0 c1 a; \ {
% O! a& u+ a8 y) v: L ~$ F //如果是文件夹中仍有文件夹,迭代之0 W3 k8 F- @2 {6 @2 a/ M$ `
//如果不是,加入列表! P0 u, e7 s) Y( A$ l8 p; p8 ~7 u& X* U
// 不推荐使用,硬要使用的话,需要修改else 里面的语句" ]6 i' e8 M6 L/ e
if((fileinfo.attrib & _A_SUBDIR))
3 W' I7 l3 b. \ {9 T: k. H8 H9 h
- S( Q# J' n7 C if(strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0)
2 F! Y9 V6 r5 w CONFIG_getFiles( pathName.assign(path).append("\\").append(fileinfo.name), exd, files );7 ~. O c0 x/ B9 Q# \
* l/ G3 `3 h0 z1 B4 ~* E& N- U }1 v0 J* [9 N. d7 h/ @
else ) h1 K* b/ X) J1 Y* O5 T
{% m; ^. A* y: M( o- P* f
if (strstr(fileinfo.name,exd.c_str()))
5 i9 {! p" [0 s; Y {. s0 k+ S8 a' e6 i4 M. I1 x
files.push_back(pathName.assign(path).append("\\").append(fileinfo.name)); // 要得到绝对目录使用该语句
0 @* Y, {) [, j, p& {( L1 ^ }; J2 M5 B) H% G- C" _, c
; y9 P% N+ ?- Q+ }; I
//如果使用
4 c: D# [5 I5 R$ G6 T // files.push_back(fileinfo.name); // 只要得到文件名字使用该语句4 ^0 u8 V% d: M* U* V9 ~: Z
}% v V+ v( {) T; R- J4 P
}while(_findnext(hFile, &fileinfo) == 0);
, v- O( ~7 O1 O8 {4 g% k# U+ M6 t _findclose(hFile);0 u. b( x `4 w4 \# j( z
}
" D) W( n7 g1 F) m; A& {}
( Q8 O) C- [ g, i[/mw_shl_code]
0 d3 U9 c, t" S. [6 {1 M |
|