zoukankan      html  css  js  c++  java
  • 文件夹遍历文件列表

    实在不知道该怎么起标题了,类似遍历一个文件夹然后获得该文件夹下的文件列表,可以随意切换文件目录,是个不是特别大的东西,本来是用在我们小组写的简易ftp服务器上的一个给客户端显示的一个小插件一样的东西?总之单拿出来应该没啥含量,调用了windows的一些API

    头文件包的有些多了,有的没用,是之前自己的音乐播放器里面的带的东西。。。

      1 #include<iostream>
      2 #include<stdlib.h>
      3 #include<windows.h>
      4 #include<mmsystem.h>  
      5 #include<string>
      6 #include<time.h>
      7 #include<fstream>
      8 #include<stdio.h>
      9 #include<vector>
     10 #include<string>
     11 #pragma comment (lib, "winmm.lib")
     12 using namespace std;
     13 
     14 void MainMenu()
     15 {
     16     printf("请选择操作
    ");
     17     printf("1.显示当前文件夹的所有文件
    ");
     18     printf("2.返回上一级
    ");
     19     printf("3.进入文件夹
    ");
     20     printf("4.进入指定文件夹
    ");
     21     printf("5.退出
    ");
     22 }
     23 void ShowFileList(string filename)
     24 {
     25     WIN32_FIND_DATAA p;
     26     vector<string> filelist;
     27     HANDLE h = FindFirstFileA(filename.c_str(), &p);
     28     filelist.push_back(p.cFileName);
     29     while (FindNextFileA(h, &p))
     30     {
     31         filelist.push_back(p.cFileName);
     32         if (filelist.back() == "." || filelist.back() == "..")
     33         {
     34             filelist.pop_back();
     35         }
     36     }
     37     for (int i = 0; i < filelist.size(); i++)
     38     {
     39         cout << filelist[i] << endl;
     40     }
     41 }
     42 
     43 void ShowLastFileList(string & filepath)
     44 {
     45     string filepath2 = filepath;
     46     string tmp = "../";
     47     tmp += filepath2;
     48     filepath = tmp;
     49     ShowFileList(tmp);
     50 }
     51 void ShowSelectFileList(string filepath)
     52 {
     53     string yourchoose;
     54     cin >> yourchoose;
     55     yourchoose += '/';
     56     string filepath2 = filepath;
     57     yourchoose += filepath2;
     58     ShowFileList(yourchoose);
     59 }
     60 void case4(string filepath)
     61 {
     62     string filename;
     63     cin >> filename;
     64     filename += '/';
     65     filename += filepath;
     66     ShowFileList(filename);
     67 }
     68 int main()
     69 {
     70     string filepath;
     71     filepath = "*.*";
     72     string filePath = filepath;
     73     while (1)
     74     {
     75         system("CLS");
     76         MainMenu();
     77         int n;
     78         cin >> n;
     79         switch (n)
     80         {
     81         case 1:
     82             system("CLS");
     83             ShowFileList(filePath);
     84             system("pause");
     85             break;
     86         case 2:
     87             system("CLS");
     88             ShowLastFileList(filePath);
     89             system("pause");
     90             break;
     91         case 3:
     92             system("CLS");
     93             ShowSelectFileList(filePath);
     94             system("pause");
     95             break;
     96         case 4:
     97             system("CLS");
     98             case4(filepath);
     99             system("pause");
    100             break;
    101         case 5:
    102             exit(0);
    103             break;
    104         default:
    105             break;
    106         }
    107     }
    108     return 0;
    109 }
  • 相关阅读:
    极客时间-左耳听风-程序员攻略-异步I/O模型和Lock-Free编程
    将SSRF升级为RCE(AWS环境)
    PowerShell ISE/文件名解析缺陷远程执行代码漏洞#RCE
    利用工具破解HTTP身份验证的多种方法
    ICMP shell
    CVE-2018-19386:SolarWinds数据库性能分析器中反射的XSS
    Recon ASRC Conference
    Python扫描器-爬虫基础
    The Bug Hunters Methodology v3(ish)
    svn状态图标大全
  • 原文地址:https://www.cnblogs.com/lenomirei/p/5481845.html
Copyright © 2011-2022 走看看