2

Here is an image that shows the structure of my folder: enter image description here

So, I basically want to copy and paste all the jpg. files in ID1. As shown in the image, there are two ID1 sub folders (highlighted yellow) that contains the jpg. files that I want.

I have a few struggles:

1) I only know how to copy one image specifically from one path

CFileStatus status;
CString strFileName = m_Values.LotID + _T(".jpg");
CString strFilePath = m_strImagePath + _T("\\") + strFileName;                      
CString strCopyPath = m_strCopyPath + _T("\\") + strFileName;
if(CFile::GetStatus(strFilePath, status))
{
    CopyFile(strFilePath, strCopyPath, FALSE);
}

2) I do not know how to iterate through all the sub folders to look for ID1 & its contents. (Because I don't know, I've no example codes to start with)

Output:

Let's say, I'm able to extract all the .jpg files from ID1 & paste into Folder2, the folder structure should look a little like this: enter image description here

Since I did not provide much of code, I don't expect a full code to solve the problem. Any explanation or insights would be adequate. Do help me out & thank you in advance.

Community
  • 1
  • 1
Sin Han Jinn
  • 574
  • 3
  • 18
  • 2
    Perhaps [this question](https://stackoverflow.com/questions/1520769/mfc-get-folders) can get you started. – 1201ProgramAlarm Nov 05 '19 at 04:27
  • 2
    Another example https://stackoverflow.com/a/916986/4603670 – Barmak Shemirani Nov 05 '19 at 05:01
  • 1
    So you basically want to list the files in a directory? – Jabberwocky Nov 05 '19 at 08:22
  • @1201ProgramAlarm Thanks for the head start! I've completed the code with your help – Sin Han Jinn Nov 05 '19 at 08:39
  • @BarmakShemirani the example was exactly what I needed. So, thanks! – Sin Han Jinn Nov 05 '19 at 08:39
  • @Jabberwocky I've done it already. Yes, iterate through every file to copy specific files. – Sin Han Jinn Nov 05 '19 at 08:40
  • 1
    Firstly, you should use something like `CFindFile` https://learn.microsoft.com/en-us/cpp/mfc/reference/cfilefind-class?view=vs-2019 to look for a list of files and iterate them. Secondly, you should look at using **recursion** https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=2ahUKEwjchvG9kdTlAhUMqxoKHXYcCKMQFjAAegQIARAB&url=https%3A%2F%2Fbeginnersbook.com%2F2017%2F08%2Fcpp-recursion%2F&usg=AOvVaw3B-uNqcUdL87V5pQ0vt1f2 where you call the same function inside the function. This way you go down nested levels into sub folders. – Andrew Truckle Nov 05 '19 at 22:39

0 Answers0