您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

如何使用C或C++获取目录中的文件列表?

2024/6/15 21:03:37发布24次查看
让我们考虑以下 c++ 示例代码来获取目录中的文件列表。
算法begin declare a poniter dr to the dir type. declare another pointer en of the dirent structure. call opendir() function to open all file in present directory. initialize dr pointer as dr = opendir("."). if(dr) while ((en = readdir(dr)) != null) print all the file name using en->d_name. call closedir() function to close the directory.end.
示例#include <iostream>#include <dirent.h>#include <sys/types.h>using namespace std;int main(void) { dir *dr; struct dirent *en; dr = opendir("."); //open all directory if (dr) { while ((en = readdir(dr)) != null) { cout<<" \n"<<en->d_name; //print all directory name } closedir(dr); //close all directory } return(0);}
输出binsearc.cbintree (1).cbintree.cbtree.cbubble.cc.txtfile3.txtheap.cheapsort.chlinklst.cinsertio.clinklist.clinklst.cllist1.cplayers.cpppolarrect.cppqueue.c
示例#include <stdio.h>#include <dirent.h>int main(void) { dir *dr; struct dirent *en; dr = opendir("."); //open all or present directory if (dr) { while ((en = readdir(dr)) != null) { printf("%s\n", en->d_name); //print all directory name } closedir(dr); //close all directory } return(0);}
输出binsearc.cbintree (1).cbintree.cbtree.cbubble.cc.txtfile3.txtheap.cheapsort.chlinklst.cinsertio.clinklist.clinklst.cllist1.c
以上就是如何使用c或c++获取目录中的文件列表?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product