File searching

I would like to get perticular extension of files from root & also from its subdirectories? I want to do this in SDK
kmoorthyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SubramanyaCommented:
You can  do it using recursive
algorithm.
If you are using MFC use
"CFilefind" class if you are not
using MFC there are equivalent API
calls .Search those API s using
MSDN.
   Next using these APIs or class
you will get all the files and directories one bye one  for a directory
that you mension.If it is a directory that you have got while searching you
have to do the same recursively.
you can use only the required files
checking extensions and  can regect
other files.Make sure you will also
get .&.. files along with other
files,neglect these files also.

If you want the recursive algorithm i
 can tell you for increased points,Mean while try to do it for one directory.
Good luck!
0
SadhuCommented:
Look at example 17 on following link

http://home.earthlink.net/~railro/mfc_link.html

Sadhu
0
kmoorthyAuthor Commented:
I want to do it using SDK. I already tried for one directory & it is working in SDK.  But in SDK I am not able solve
it from root dirctory.
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

SubramanyaCommented:
Send the code you have.
I will give you the Answer.And ask the
Problem clearly.
0
kmoorthyAuthor Commented:
HANDLE l_hFileFind;
 BOOL l_Find ;
                    
 l_hFileFind = FindFirstFile("c:/songs/*.txt", &l_FindFileData);
                  
  if(l_hFileFind == INVALID_HANDLE_VALUE)
{
                          MessageBox(hDlg, "Find failed", NULL, NULL);
                          return TRUE;
 }

  while(FindNextFile(l_hFileFind, &l_FindFileData) != 0 )
 {      
MessageBox(hDlg, TEXT(l_FindFileData.cFileName ), NULL, NULL);
 }
  return TRUE;
0
brandtsCommented:
Try this:

void FindFilesWithExtension(char* szPath)
{
     char szMask [MAX_PATH];
     ::strcpy(szMask, szPath);
     ::strcat(szMask, "*.txt");

     WIN32_FIND_DATA FindData;
     HANDLE hFileFind = ::FindFirstFile(szPath, &FindData);

     if (hFileFind != INVALID_FILE_HANDLE)
     {
          do
          {
               if (FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
               {
                    // Found a directory.  Call this recursively to search
                    FindFilesWithExtension(FileData.cFileName);
               }
               else
               {
                    // Found a file.  Display a message box.
                    MessageBox(FindData.cFileName, NULL, NULL);
               }
          }
          while (::FindNextFile(hFileFind, &FindData);
     }
     else
     {
          // Find failed.  Display a message box
          MessageBox("Find failed", NULL, NULL);
     }

     ::FindClose(hFileFind);
}

I haven't run this through the compiler, but the general idea is there.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kmoorthyAuthor Commented:
Thx. For giving the info.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.