Home > Software engineering >  For help! Traverse a TXT file folder, and the content of the random read a TXT. Assign a value to a
For help! Traverse a TXT file folder, and the content of the random read a TXT. Assign a value to a

Time:09-18

BOOL CWebDlg: : OnInitDialog ()
{
CDialog: : OnInitDialog ();

//Add "About... "Menu item to system menu.

//IDM_ABOUTBOX must be in the system command range.
ASSERT ((IDM_ABOUTBOX & amp; 0==IDM_ABOUTBOX xfff0));
ASSERT (IDM_ABOUTBOX & lt; 0 xf000);

CMenu * pSysMenu=GetSystemMenu (FALSE);
If (pSysMenu!=NULL)
{
Cstrings strAboutMenu;
StrAboutMenu. LoadString (IDS_ABOUTBOX);
if (! StrAboutMenu. IsEmpty ())
{
PSysMenu - & gt; The AppendMenu (MF_SEPARATOR);
PSysMenu - & gt; AppendMenu (MF_STRING IDM_ABOUTBOX, strAboutMenu);
}
}

//Set the icon for this dialog. The framework does this automatically
//when the application 's main window is not a dialog
SetIcon (m_hIcon, TRUE);//Set the big icon
SetIcon (m_hIcon, FALSE);//Set the small icon

//TODO: Add extra initialization here
FfFile (" ", "TXT")

Return TRUE;//return TRUE unless you set the focus to a control
}


This is the code, the system automatically added ffFile (" ", "TXT"), because add the press F9, and F5 to debug, to grab, I can read the following program folder, first the colon to fill the folder, a second what to fill?





I just contact with vc + +, please can you tell
In front of the
Void CWebDlg: : ff (cstrings strDir, cstrings strExt)
{
Static int I=0, j=0;
CFileFind fileFinder.
Cstrings strWildcard=strDir;

(1) if (strWildcard. Right!
="\ ")StrWildcard +="\ ";
StrWildcard +="*. *";


BOOL fSuccess=fileFinder. FindFile (strWildcard);

While (fSuccess)
{
FSuccess=fileFinder. FindNextFile ();

{if (fileFinder. IsDots ())
The continue;
}

If (fileFinder. IsDirectory ())
{

Ff (fileFinder. GetFilePath (), strExt);//recursive call
}
The else
{

Cstrings fpath [1024].
Cstrings fname [1024].
Int artnum;
Cstrings strFilePath=fileFinder. GetFileName ();
If (0==strExt.Com pareNoCase (PathFindExtension (strFilePath)))
{
Fpath [i++]=strFilePath;
Fname [j++]=fileFinder. GetFileName ();
Artnum++;
}
}
}

FileFinder. Close ();

CodePudding user response:

Example
 
Typedef struct the FileInfo
{
String szFileName;
String szFilePath;
String szCreateTime;
} the FileInfo;

Vector The fileList;

//
Void the find (LPCTSTR lpPath vector & FileList)
{
String szFind (lpPath);
WIN32_FIND_DATA FindFileData;
SzFind +=_T (" \ \ *. * ");
HANDLE hFind=: : FindFirstFile (szFind c_str (), & amp; FindFileData);
If (INVALID_HANDLE_VALUE=https://bbs.csdn.net/topics/=hFind) return;
//
Do
{
If (FindFileData dwFileAttributes & amp; FILE_ATTRIBUTE_DIRECTORY)
{//dir
If (FindFileData cFileName [0]! )
='. '{
String szPath (lpPath);
SzPath +=_T (" \ \ ");
SzPath +=FindFileData. CFileName;
//TRACE1 (" % s \ n ", szPath c_str ());
Find (szPath. C_str (), the FileList);
}
}
The else
{//file
String strFileName=FindFileData. CFileName;//file name
//TRACE1 (" % s \ n ", strFileName c_str ());
Int the at=strFileName. Find_last_of (');
If (at<0) continue;//file without extention
String ext.=strFileName substr (at);
//TRACE1 (" % s \ n ", ext c_str ());
//
The at=0;//reset
While (((int) at=suffixStr. Find (ext, ats)) & gt;=0)//find the type
//if (stricmp (suffixStr c_str (), _T (". TXT "))==0)
{//not suffixStr. C_str ()==_T (". TXT "); Never==!
//afxDump & lt; The at +=ext size ();//move to seperetor '
If (suffixStr [at]!=') continue;//not wanted!
//
FILETIME ft=FindFileData. FtCreationTime;
SYSTEMTIME st={0};
TCHAR buf [64]={0};
FileTimeToLocalFileTime (& amp; (FindFileData. FtCreationTime), & amp; Ft);
FileTimeToSystemTime (& amp; The ft, & amp; St);
Sprintf (buf, _T (" % % 4 d years 02 02 on 02 d % d % d: % 02 d: % 2 d "),
St. wYear, st. wMonth, st. wDay, st. wHour/* */Beijing time, st. wMinute, st. wSecond);
String strFilePath=lpPath;
The FileInfo fi;
Fi. SzFileName=strFileName;
Fi. SzFilePath=strFilePath;
Fi. SzCreateTime=buf;
//TRACE1 (" % s \ n ", strFileName c_str ());
FileList. Push_back (fi);
}
}
} while (: : FindNextFile (hFind, & amp; FindFileData));
}