All files under the directory (Windows, Hyper-detail)

Source: Internet
Author: User
Tags filetime

Note: This article discusses how to use the Windows API to traverse all files in the directory. In addition to the Windows API, there is a windows/linux common way to use <io.h>.

Win32_find_data structure

The WIN32_FIND_DATA structure is required to traverse the files in the directory. There are actually two kinds of structures: Win32_find_dataa and Win32_find_dataw. A and W represent ASCII and wide characters (Unicode), respectively. When defining a Unicode macro, win32_find_data refers to Win32_find_dataw; otherwise, it refers to Win32_find_dataa.

The following is a definition of two structures (minwinbase.h,vs2015):

typedefstruct_win32_find_dataa {DWORD dwfileattributes;    FILETIME Ftcreationtime;    FILETIME Ftlastaccesstime;    FILETIME Ftlastwritetime;    DWORD Nfilesizehigh;    DWORD Nfilesizelow;    DWORD dwReserved0;    DWORD dwReserved1;    _field_z_ CHAR cfilename[MAX_PATH]; _field_z_ CHAR calternatefilename[ -]; #ifdef _mac DWORD Dwfiletype;    DWORD Dwcreatortype; WORD wfinderflags;#endif} win32_find_dataa;typedefstruct_win32_find_dataw {DWORD dwfileattributes;    FILETIME Ftcreationtime;    FILETIME Ftlastaccesstime;    FILETIME Ftlastwritetime;    DWORD Nfilesizehigh;    DWORD Nfilesizelow;    DWORD dwReserved0;    DWORD dwReserved1;    _field_z_ WCHAR cfilename[MAX_PATH]; _field_z_ WCHAR calternatefilename[ -]; #ifdef _mac DWORD Dwfiletype;    DWORD Dwcreatortype; WORD wfinderflags;#endif} Win32_find_dataw;

The part about the _MAC macro can be ignored, for historical reasons-roost Microsoft is the largest developer of Macs, and for the convenience of porting apps on Windows to a Mac, use _mac macros, if the Mac operating system _mac is defined. (according to Stack Overflow) because this is about Windows, let's put this aside.

The following are the meanings of each struct member:

dwFileAttributes

The file attributes of a file.

File Property constants:

File_attribute_archive (0x20): A file or directory is an archive file or directory. The application uses this property to tag the file, indicating backup or removal.
File_attribute_compressed (0x800): The file or directory is compressed. For a file, all of the data is compressed. For a directory, the default compression for newly created files and subdirectories.
File_attribute_directory (0x40): This value is reserved for use by the system.
File_attribute_directory (0x10): marks a handle to a directory.
File_attribute_encrypted (0x10): The file or directory is encrypted. For a file, all data streams are encrypted. For a directory, the default encryption for newly created files and subdirectories.
File_attribute_hidden (0x2): The file or directory is hidden. They are not generally considered when traversing folders.
File_attribute_integrity_stream (0x8000):

(To is continued, do not reproduce)

All files under the directory (Windows, Hyper-detail)

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.