CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2004
    Posts
    21

    How can i write function that search for file on the disk ?

    Hi,

    I want to write some application that looking some file name ( "file.exe" or "*.exe" ) on the entire disk.

    Can some one help me ?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: How can i write function that search for file on the disk ?

    Take a look at CFileFind class

  3. #3
    Join Date
    May 2005
    Posts
    4,954

    Re: How can i write function that search for file on the disk ?

    Please dont cross post the same question you already got an answer here.

    Cheers
    If a post helped you dont forget to "Rate This Post"

    My Article: Capturing Windows Regardless of Their Z-Order

    Cheers

  4. #4
    Join Date
    Aug 2001
    Posts
    507

    Re: How can i write function that search for file on the disk ?

    Here this is how u do it.

    Code:
    char szPath[MAX_PATH];
    	BROWSEINFO lpbi;
    	::ZeroMemory(&lpbi,sizeof(BROWSEINFO));
    	
    	ITEMIDLIST *folder  =  ::SHBrowseForFolder(&lpbi);
    	
    	::SHGetPathFromIDList(folder,szPath);
    
    	CFileDialog cd(1,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,NULL,NULL);
    	cd.DoModal();
    	
    
    	
    	CString sFullMask = szPath + CString("\\*.*");
    	list<string> ldf;
    	CFileFind finder;
    
    	bool bFound;
    	bFound=finder.FindFile(sFullMask);
    
    	while ((bFound))
    	{
    		bFound = finder.FindNextFile();
    		if (!finder.IsDots())
    		{
    					
    			// Add file to list
    			string sName = finder.GetFilePath();
    			if (finder.IsDirectory()) sName += "\\";
    				ldf.push_back(sName);
    		
    			
    					
    		}
    	}
    If u dont want to use string<> u can use some ting else ...
    If you found my reply to be useful, please dont hesitate to rate it.


    DO NOT kick the Axe if it doesnt fall on your foot.

    Salman

  5. #5
    Join Date
    Oct 2005
    Location
    Bangalore
    Posts
    1,051

    Re: How can i write function that search for file on the disk ?

    Check out this wonderful FAQ

    PS: Please do make it a habbit to use the search option.
    - Sreehari
    "Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us."
    " Everybody is sent to Earth on a purpose. I am so Lagging behind that i won't die." – Calvin

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