title: problems with searching in files and directories .. windows programming
body: <p>I'm studying this book (Addison Wesley Windows System Programming 4th Edition) and I think its useless Im working on a searching code that support the recursive so it can go in deepth in files and directories the code is working ( I guess ) no syntax error but the output is not what I want the out put of the search is like:</p>
  
  <pre><code>    not found
  Now, here are the folders:
  not found
  Searching in d:\iust\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
  \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
  \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
  \.\.\.\.\.\..\e-books\.\.\.\.\E-BOOKS
  The file name is: d:\iust\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
  .\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
  .\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
  .\.\.\.\.\.\.\.\..\e-books\.\.\.\.\E-BOOKS\*Test*
  not found
  Now, here are the folders:
  not found
  Searching in d:\iust\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
  \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
  \.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.
  \.\.\.\.\.\..\e-books\.\.\.\..
  The file name is: d:\iust\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
  .\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
  .\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\.\
  .\.\.\.\.\.\.\.\..\e-books\.\.\.\..\*Test*
  not found
  Now, here are the folders:
  </code></pre>
  
  <p>First I notiiced that what ever I do it will not search just inside the folder i specified but in all whole drive and the second annoying probem is the DOTS the . and .. those appear in each folder how can I avoid this problem. now as i said before Im using the book I mentioned before but I dont know I just dont like what i did is there a better way to form my code .</p>
  
  <p>the code :</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;windows.h&gt;
  
  void SearchForFile(TCHAR *folder, TCHAR *file){
      _tprintf(L"Searching in %s\n",folder); //just to show the state
      TCHAR temp[1000];
  
      _stprintf(temp,L"%s\\%s",folder,file); // here  wrote into temp the location as folder/file
      _tprintf(L"The file name is: %s\n",temp);
      HANDLE f;
      WIN32_FIND_DATA data;
      f=FindFirstFile(temp,&amp;data);
      if(f==INVALID_HANDLE_VALUE){
          _tprintf(L"not found\n");
  
      }
      else{
          _tprintf(L"found this file: %s\n",data.cFileName);
          while(FindNextFile(f,&amp;data)){
              _tprintf(L"found this file: %s\n",data.cFileName);
          }
          FindClose(f);   
      }
  
      _stprintf(temp,L"%s\\*",folder); // "d:\*" for example
      _tprintf(L"Now, here are the folders:\n");
      f=FindFirstFile(temp,&amp;data);
      TCHAR temp2[1000];
      if(f==INVALID_HANDLE_VALUE){
          _tprintf(L"not found\n");
  
      }
      else{
          if((data.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) != 0)
              {
  
              //_tprintf(L"found this directory: %s\n",data.cFileName);
                  _stprintf(temp2,L"%s\\%s",folder,data.cFileName);
                  SearchForFile(temp2,file);
              }
          while(FindNextFile(f,&amp;data)){//         _tprintf(L"%d   %d\n",data.dwFileAttributes,FILE_ATTRIBUTE_DIRECTORY);
              if((data.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY) != 0)
              //  _tprintf(L"found this directory: %s\n",data.cFileName);
              {
                  _stprintf(temp2,L"%s\\%s",folder,data.cFileName);
                  SearchForFile(temp2,file);
  
              }
          }
          FindClose(f);   
      }
  }
  
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      SearchForFile(L"d:\\test", L"*Test*");
      return 0;
  }
  </code></pre>