Folder traversal file list, traversing list

Source: Internet
Author: User

Folder traversal file list, traversing list

I really don't know how to start the title. It is similar to traversing a folder and getting the file list under the folder. You can switch the file directory at will, which is not very big, is it a small plug-in that is originally used on a simple ftp server written by our group to display to the client? In a word, the ticket should have no content, and some windows APIs are called.

Some of the header file packages are too many, and some are useless. They are included in your own music player...

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 (" Select Operation \ n "); 17 printf (" 1. show all files in the current Folder \ n "); 18 printf (" 2. return Level \ n "); 19 printf (" 3. enter the Folder \ n "); 20 printf (" 4. enter the specified folder \ n "); 21 printf (" 5. exit \ n "); 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 exit (0); 103 break; 104 default: 105 break; 106} 107} 108 return 0; 109}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.