CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 16

Threaded View

  1. #9
    Join Date
    Feb 2012
    Posts
    16

    Re: Strings in VC++ 6

    Hi

    Im wring a code to search if my website has been downloaded by IE or not, this is done by searching a file recursive inside "c:\\Documents and Settings\\"+userName+"\\Local Settings\\Temporary Internet Files\\Content.IE5";

    I wanted to make it recursive search for a file name (abc.jpg) , i wrote this code (based on ovidiucucu's code), but its seems to be not working .
    Code:
    #include "stdafx.h"
    #pragma warning(disable: 4786)
    
    #include <iostream>
    #include <string>
    #include <list>
    
    using namespace std;
    
    void list_folder(string sFolderPtr, list<string>& lFileNames)
    {
       string& sFolder = sFolderPtr;
       string sFind = sFolder + "\\*.*"; 
       WIN32_FIND_DATA findData = {0};
       HANDLE hFileFind = ::FindFirstFileA(sFind.c_str(), &findData);   
       if(INVALID_HANDLE_VALUE != hFileFind)
       {	  
    	   
    	   do
          {		
    		string fileName = findData.cFileName;
    
    		if ( fileName.compare("accountmsg"))
    			cout << "Account msg found" ;
    		string tempBuff="";
    		if (!strcmp(findData.cFileName , ".")) continue ;
    		if (!strcmp(findData.cFileName , "..")) continue ;		
    		//cout << "\n This is boolean value (" << findData.cFileName << ") : " << hex << (findData.dwFileAttributes);// == FILE_ATTRIBUTE_COMPRESSED);
    		if ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY){				
    			
    			string buff = "";
    			buff = sFolder + "\\" + findData.cFileName ;			
    			list_folder(buff,lFileNames);
    		} // if          
    
          }while(::FindNextFileA(hFileFind, &findData));
    	  //lFileNames.push_back((string)buff);
       }
       FindClose(hFileFind);
    }
    
    
    int main()
    {
    
    	string userName = (char*) getenv("username"); // temp Directory   
    	string defaultTempPath = "c:\\Documents and Settings\\"+userName+"\\Local Settings\\Temporary Internet Files\\Content.IE5";
    	string rootDir = "Content.IE5";  
     
    
    
    	   cout << "Starting \n";
    	   string sFolder = defaultTempPath;
    	   list<string> lFileNames;
    
    	   list_folder(sFolder, lFileNames);
    
    	   list<string>::const_iterator iter;
    	   const list<string>::const_iterator end = lFileNames.end();
    	   for(iter = lFileNames.begin(); iter != end; ++iter)
    	   {
    		 // cout << (*iter).c_str() << endl;
    	   }
    
    
      
    	return 0;
    }
    there is not error , but no desired output as well ....


    regards
    Last edited by ovidiucucu; February 29th, 2012 at 01:02 AM. Reason: added [CODE] tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured