Use Windows API functions to get all file names under directory---directories under scan and processing

Source: Internet
Author: User

Directly on the code

Test_max.cpp: Defines the entry point of the console application. #include "stdafx.h" #include <windows.h> #include <Shlwapi.h> #include <iostream> #include < string> #include <vector> #pragma comment (lib, "Shlwapi.lib")//Note the placement of the position using namespace Std;void findfile ( String dir) {Win32_find_dataa stfd;//The structure that holds the file information handle h;string temp;temp=dir+ "\\*"; H=findfirstfilea (Temp.c_str (), &STFD);//build directory handle while (Findnextfilea (H,&STFD))//extract directory handle corresponding directory contains file {temp=dir+ "\ \" +stfd.cfilename;if (temp== dir+ "\ \.") Upper-level path {continue;} else if (Pathisdirectorya (Temp.c_str ()))//contains subdirectories {findfile (temp);//Recursive call}else{cout<<stfd.cfilename<< endl;//print file name}}return;} int main (void) {string dir;dir= "F:\\datasets\\match gallery"; FindFile (dir); system ("pause"); return 0;}
You can do what you want after you know the file name and path name

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.