Home > Software engineering >  For help! For help! How in the MFC in a fixed part of the folder name according to the pictures, fin
For help! For help! How in the MFC in a fixed part of the folder name according to the pictures, fin

Time:09-25

In MFC, because the picture of the folder each name is different, I think in a fixed folder, part of the name according to the pictures, all the pictures to find the name how to write?

CodePudding user response:

Find files CFileFind

CodePudding user response:

Define a CFileFind object,
Use CFileFind: : FindFile start search, file name use wildcards,
It then calls the FindNextFile,
If found, using GetFileName return accurate file name

CodePudding user response:

System (" dir/b/a - d c: \ \ *. * & gt; D: \ \ allfiles TXT ");
//read file d: \ \ allfiles TXT content of C: \ \ under the names of all files
System (" dir/b/a - d/s c: \ \ *. * & gt; D: \ \ allfilesinsub TXT ");
//read file d: \ \ allfilesinsub TXT content that is C: \ \ under the names of all files contain subdirectories
System (" dir/b/active directory c: \ \ *. * & gt; D: \ \ alldirs TXT ");
//read file d: \ \ alldirs TXT content of C: \ \ under the names of all the subdirectories
Please remember, can use the shell command to get the file and folder information or manipulate files, folders had better use the shell command to get or operation, and don't use all sorts of API access to or operation, because when it comes to illegal folder name or illegal filename or illegal file length, illegal file date, compressed file, link files, sparse file... All sorts of unexpected situations, such as API can deal with incomplete or into an infinite loop, and shell commands not,
If disrelish black window system that the system ("... ") is replaced by WinExec (" CMD/c... ", SW_HIDE);

CodePudding user response:

 
/*
Author: shiyanbo 2018-02-08
The function name: ReadFileFromFolder
Input param: strFoledrPath
The out param: no
Fancy: according to the input directory for the current directory of all file contains a folder and the all files underneath, until the bottom
The return value of NULL
*/
Void CDlgCheckImgResult: : ReadFileFromFolder (cstrings & amp; StrFoledrPath)
{
WIN32_FIND_DATA FindData;
HANDLE hError.

Char FilePathName [MAX_PATH];

ZeroMemory (FilePathName, sizeof (FilePathName));

Strcpy (FilePathName, strFoledrPath);
Strcat (FilePathName, "\ \ *. *");
HError=: : FindFirstFile (FilePathName, & amp; FindData);

If (hError==INVALID_HANDLE_VALUE)
{
//cout & lt; <" Failed to find file "& lt; return ;
}

While (: : FindNextFile (hError, & amp; FindData))
{
//filter. And..
If (0==STRCMP (FindData cFileName, "") | | 0==STRCMP (FindData cFileName,"..
")){
continue;
}

//file name
Cstrings strFileName;
//filter directory
If (FindData dwFileAttributes & amp; FILE_ATTRIBUTE_DIRECTORY)
{
StrFileName. The Format (" % s ", FindData cFileName);
Cstrings strFullFileName=strFoledrPath + "\ " + strFileName;
//this is a directory, and continue to traverse the read the file
ReadFileFromFolder (strFullFileName);
continue;
}

StrFileName. The Format (" % s ", FindData cFileName);
Int pos=strFileName. ReverseFind (');

//the images and directory
If (1==pos)
{
The continue;
}
The else
{
StrFileName=strFileName. Mid (pos + 1, strFileName GetLength () - pos - 1);
if (! StrFileName.Com pare said (IMAGE_TYPE_JPG) | |! StrFileName.Com pare said (IMAGE_TYPE_PNG) | |! StrFileName.Com pare said (IMAGE_TYPE_BMP) | |! StrFileName.Com pare said (IMAGE_TYPE_TIFF))
{
Cstrings strFullPathName;
//structure complete path
StrFullPathName. The Format (" % s \ \ % s ", strFoledrPath, FindData. CFileName);
VceImageSumResult. Push_back (strFullPathName);
}
The else
{
The continue;
}
}
}
}

CodePudding user response:

To find qualified pictures above, showed yo GDI +, CXimage or opencv is with you in the mood

CodePudding user response:

Do you want to find complete filename of the image file??
  • Related