文件夹遍历文件列表
2016-05-11 14:46
190 查看
实在不知道该怎么起标题了,类似遍历一个文件夹然后获得该文件夹下的文件列表,可以随意切换文件目录,是个不是特别大的东西,本来是用在我们小组写的简易ftp服务器上的一个给客户端显示的一个小插件一样的东西?总之单拿出来应该没啥含量,调用了windows的一些API
头文件包的有些多了,有的没用,是之前自己的音乐播放器里面的带的东西。。。
头文件包的有些多了,有的没用,是之前自己的音乐播放器里面的带的东西。。。
#include<iostream> #include<stdlib.h> #include<windows.h> #include<mmsystem.h> #include<string> #include<time.h> #include<fstream> #include<stdio.h> #include<vector> #include<string> #pragma comment (lib, "winmm.lib") using namespace std; void MainMenu() { printf("请选择操作\n"); printf("1.显示当前文件夹的所有文件\n"); printf("2.返回上一级\n"); printf("3.进入文件夹\n"); printf("4.进入指定文件夹\n"); printf("5.退出\n"); } void ShowFileList(string filename) { WIN32_FIND_DATAA p; vector<string> filelist; HANDLE h = FindFirstFileA(filename.c_str(), &p); filelist.push_back(p.cFileName); while (FindNextFileA(h, &p)) { filelist.push_back(p.cFileName); if (filelist.back() == "." || filelist.back() == "..") { filelist.pop_back(); } } for (int i = 0; i < filelist.size(); i++) { cout << filelist[i] << endl; } } void ShowLastFileList(string & filepath) { string filepath2 = filepath; string tmp = "../"; tmp += filepath2; filepath = tmp; ShowFileList(tmp); } void ShowSelectFileList(string filepath) { string yourchoose; cin >> yourchoose; yourchoose += '/'; string filepath2 = filepath; yourchoose += filepath2; ShowFileList(yourchoose); } void case4(string filepath) { string filename; cin >> filename; filename += '/'; filename += filepath; ShowFileList(filename); } int main() { string filepath; filepath = "*.*"; string filePath = filepath; while (1) { system("CLS"); MainMenu(); int n; cin >> n; switch (n) { case 1: system("CLS"); ShowFileList(filePath); system("pause"); break; case 2: system("CLS"); ShowLastFileList(filePath); system("pause"); break; case 3: system("CLS"); ShowSelectFileList(filePath); system("pause"); break; case 4: system("CLS"); case4(filepath); system("pause"); break; case 5: exit(0); break; default: break; } } return 0; }
相关文章推荐
- UIAppearance 基本使用
- Spark性能优化:资源调优篇
- RecyclerView 添加 Footer and Header
- ServerCore通过PowerShell脚本加载共享存储
- 是春哥啊
- ContentProvider入门
- iOS 不规则瀑布流
- php文件只要开始标签而不要结尾标签?
- 【第六章】 AOP 之 6.4 基于@AspectJ的AOP ——跟我学spring3
- Android中跨进程通信方式之使用AIDL进阶篇
- iOS开发 贝塞尔曲线UIBezierPath(后记)
- WPF之路——用户控件对比自定义控件UserControl VS CustomControl)
- C++枚举类型
- 在git下载的源代码运行时因为cocopods第三方库报错的解决方法
- 2009
- IOS中获取各种文件的目录路径的方法
- Android获取屏幕的实际大小
- 客户端的全局变量Cookie,JS设置、读取、删除cookie操作
- Spring 计划
- 地图类型