Use the cfindfile to traverse the directory.

xiaoxiao2021-03-05  53

OS: Win32 (Not Support Wince)

SDK: MFC

code show as below:

CFILEFIND FF;

CString szdir = m_nfilepath; // m_nfilepath is a directory IF selected by the user (szdir.right (1)! = "//") / / Make sure the last character of the directory is '/' szdir = "//"; SZDIR = "*. *";

Bool res = ff.findfile (szdir);

While (res) {res = ff.findnextFile (); if (ff.isdirectory () &&! ff.isdots ()) Continue;

Else if (! ff.isdirectory () &&! ff.isdots ()) Sprintf (stdout, "% s / n", ff.getfilename ());

} Ff.close ();

If you need to use it on Wince, you can use Platform SDK.

Win32_find_data findfiledata; handle hfind;

HFIND = :: FindfirstFile ("D: //*.*", & findFileData); if (FindFileData.dwFileAttributes! = file_attribute_directory) Sprintf (stdout, "% s / n", FindFileData.cfileName

if (! hFind = INVALID_HANDLE_VALUE) {while (FindNextFile (hFind, & FindFileData)) {if (! FindFileData.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY) sprintf (stdout, "% s / n", FindFileData.cFileName} FindClose (hFind);}

转载请注明原文地址:https://www.9cbs.com/read-36711.html

New Post(0)