CodePudding user response:
Void CTextDlg: : SelectDir ()//manually select the folder
{
//TODO: add the control notification handler code
BROWSEINFO bi;//BROWSEINFO structure members have a lot of parameters can be set
ZeroMemory (& amp; Bi, sizeof (BROWSEINFO));//will be & amp; Bi for the start address and size of sizeof (BROWSEINFO) area of memory with 0
Bi. UlFlags=BIF_NEWDIALOGSTYLE;//set the pop-up dialog box attributes.
Bi. LpszTitle="designated to deal with the folder";//within the window shows that prompt the user statement
LPITEMIDLIST pidl=SHBrowseForFolder (& amp; Bi);//Displays a dialog box enabling the user to select a Shell folder.
TCHAR * path=new TCHAR [MAX_PATH];
If (pidl!=NULL)
{
SHGetPathFromIDList (pidl, path);//Converts an item identifier list to a file system path
GetDlgItem (IDC_EDIT1) - & gt; SetWindowText (path);
The ReadDir (path);
}
Delete the path;
}
Void CTextDlg: : ReadDir (cstrings strDir)//JPG images of selected folder path
{
(1) if (strDir. Right!=_T (" \ \ "))
StrDir +=L "\ ";
StrDir=strDir + _T (" *. * ");
CFileFind finder.
Cstrings strPath;
BOOL bWorking=finder. FindFile (strDir);
While (bWorking)
{
BWorking=finder. The FindNextFile ();
StrPath=finder. GetFilePath ();
If (finder. IsDirectory () & amp; & ! Finder. IsDots ())
The ReadDir (strPath);//recursive call
Else if (! Finder. IsDirectory () & amp; & ! Finder. IsDots ())
{
//strPaht is to obtain the file path
Cstrings strTmp=strPath. Right (4);
StrTmp. MakeLower ();
If (strTmp=="log")
{
Listname. Add (strPath);//listname for global variables defined in the header file
}
}
}
Finder. The Close ();
WriteDir ();
}
Void CTextDlg: : WriteDir ()//will get a path to E://myfile. TXT in
{
Int nCount;
NCount=listname. GetSize ();
Char * pszFileName="E://myfile. TXT";
CStdioFile myFile.
CFileException fileException;
If (myFile. Open (pszFileName, CFile: : typeText | CFile: : modeCreate | CFile: : modeReadWrite), & amp; FileException)
//E://myfile. TXT does not exist, create
{
for (int i=0; i{
Cstrings strOrder;
StrOrder=listname. GetAt (I);
Cstrings strLine;
StrLine. The Format (" % s \ r \ n ", strOrder);
MyFile. WriteString (strLine);
}
}
The else
{
TRACE (" Can 't open the file % s, error=% u/n ", pszFileName, fileException. M_cause);
}
}
CodePudding user response:
Inside. The log instead. JPG