Recipe 4.9. Searching for Files or FoldersProblemYou want to find the files or folders that match certain criteria. SolutionUsing a graphical user interfaceOn Windows Server 2003, select Search from the Start menu and click All files and folders. On Windows 2000, select Search Now you'll be able to search for a particular file or folder name (use * as the wildcard) or enter one or more words to search within text-based files. Select the drive, drives, or folder you want to search. Click the Search button (or Search Now on Windows 2000). Below the Search button, you can select additional advanced search options, which allows you to search based on file timestamp, file size, and various file attributes. Using a command-line interfaceThe where.exe utility searches the files in your path that match a pattern. This command finds all files that begin with net and have a .exe extension: > where net*.exe You can also use where to find files in a specific folder or tree of folders. This command finds all .vbs scripts whose names contain the letters foo: > where /r c:\scripts *foo*.vbs Windows comes with two other tools you can use to search for files that contain a certain string: find.exe and findstr.exe. The latter is more robust. If you only need to find the files in the current directory that contain the letters log, you can use this command: > findstr log * This next command performs a case-insensitive search (/i) for all nonbinary files (/p) on the d: drive (/s) that contain the text "confidential" (/c): > findstr /s /p /i /c:"confidential" d:\* findstr includes some regular expression support. For a list of all the features, look at the command help information (findstr /?). If you want to search for strings within binary files, take a look at the Sysinternals strings.exe command. The following command displays any text strings contained in binary files within the Program Files directory: > strings -s "c:\program files" See AlsoMS KB 185476 (HOWTO: Search Directories to Find or List Files) |