/////////////////////////////////////////////////////////////// // dirsrch.cpp - search specified directory or path for file // // // // Adapted by Jim Fawcett from the book: // // "Win32 System Services: // // The Heart of Windows 95 and Windows NT", Marshall Brain, // // Prentice Hall, Copyright 1995 // // // /////////////////////////////////////////////////////////////// #include #include #include using namespace std; //----< convert string to upper case >------------------------- void upper(char *s) { int i, len = strlen(s); for(i=0; i---- void main() { char name[MAX_PATH]; char pathName[MAX_PATH]; char *pathPointer; char *p; char buffer[MAX_PATH]; DWORD len; cout << "\n Demonstrate Searching for Files " << "\n =================================\n\n"; // get name of file cout << " Enter the name of the file to find: "; cin >> name; // get name of directory to start search cout << " Enter path to start search, or PATH: "; cin >> pathName; upper(pathName); // Search named path, or system path if (strcmp(pathName, "PATH") == 0) pathPointer = NULL; else pathPointer = pathName; // // do the search. It may take a while // If pathPointer is not NULL the search will be limited to // the single directory specified -- child directories will // not be searched. // If pathPointer is NULL then the current directory, system // directories and all path directories are searched, in that // order. len = SearchPath(pathPointer, name, 0, MAX_PATH, buffer, &p); cout << " The search may take awhile..."; if (len == 0) cout << "Not found: " << GetLastError() << endl; else cout << "Found in:\n " << buffer << endl; cout << endl; }