Thread: search for file function

  1. #1
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455

    search for file function

    i have the code that will search for a file, but i don't want it to search in only 1 directory, i want it to search through the entire computer.

    anyone have any code?

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Log C: and every time the FindFirst/Next returns a directory, so search that, you could write a recursive searcher to do so, i.e. search C: if the first it finds is a directory called Alpha, so search c:\Alpha and so on.

    If you don't know how to detect if a file is a directory or not, part 3 of my searching tutorial covers it.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    i want wookie cookies the Wookie's Avatar
    Join Date
    Oct 2002
    Posts
    455
    okay thanks. heres what i have so far


    Code:
    WIN32_FIND_DATA FileData; 
    	HANDLE hSearch; 
    	DWORD dwAttrs; 
    	char szDirPath[] = "c:\\TEXTRO\\"; 
    	char szNewPath[MAX_PATH]; 
    	char szHome[MAX_PATH]; 
    	 
    	BOOL fFinished = FALSE; 
    	 
    	hSearch = FindFirstFile("C:\\*.*", &FileData); 
    	if (hSearch == INVALID_HANDLE_VALUE) 
    	{ 
    		cout<<"no files found";
    		return;
    	} 
    		 
    	while (!fFinished) 
    	{ 
    
    		cout<< FileData.cFileName<<endl;
    
    		
    
    		if (!FindNextFile(hSearch, &FileData)) 
    		{
    			if (GetLastError() == ERROR_NO_MORE_FILES) 
    			{ 
    				cout<<"no more files\n";
    				fFinished = TRUE; 
    			} 
    			else 
    			{ 
    				cout<<"couldnt find next file";
    				return;
    			} 
    		}
    	} 
    	 	 
    	FindClose(hSearch);

    what i really want is something like the dos "tree" command

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Attempt to write function search()
    By elsewhere in forum C Programming
    Replies: 6
    Last Post: 12-03-2008, 08:18 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 03:33 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM