Under Windows, use the FindFirstFile and FindNextFile functions. They load a WIN32_FIND_DATA structure that contains details of each file and directory, so you select the files of interest to you based on the content of that structure, for instance directories, hidden files, system files, and so on.
qWake
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you qWake. I am new to this forum, and you are always very helpful. I found the structure, but I am not sure if this is all of it.
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
Is that it? Also, how do I know if it is a sub-folder or hidden file etc? I want to do something different by type. The only thing I see is the attributes field, so I am assuming this is the field to tell me these things. But I can't find the values and what they mean after googling for a while. Do you know?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This second page has sample code to do what you want: to list the files in a directory. Flags for the various types are as you suspected: in the dwFileAttributes double word.
qWake
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I wish to add code to list all files in a directory into my C++ program. I am using Dev-C++. Can anyone help me?
Thanks, Brian
Under Windows, use the FindFirstFile and FindNextFile functions. They load a WIN32_FIND_DATA structure that contains details of each file and directory, so you select the files of interest to you based on the content of that structure, for instance directories, hidden files, system files, and so on.
qWake
Thank you qWake. I am new to this forum, and you are always very helpful. I found the structure, but I am not sure if this is all of it.
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[ MAX_PATH ];
TCHAR cAlternateFileName[ 14 ];
Is that it? Also, how do I know if it is a sub-folder or hidden file etc? I want to do something different by type. The only thing I see is the attributes field, so I am assuming this is the field to tell me these things. But I can't find the values and what they mean after googling for a while. Do you know?
Look at the MSDN reference for these two functions and you will see the details for the structure too. Specifically, look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findfirstfile.asp
and here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/base/findnextfile.asp
This second page has sample code to do what you want: to list the files in a directory. Flags for the various types are as you suspected: in the dwFileAttributes double word.
qWake