[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

File searching

I would like to get perticular extension of files from root & also from its subdirectories? I want to do this in SDK
0
kmoorthy
Asked:
kmoorthy
1 Solution
 
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
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
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
 
kmoorthyAuthor Commented:
Thx. For giving the info.
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now