Use 'whereis' command in Windows xp

          'Whereis' command in Windows Vista searches a file in directory included in 'path' environment variable. We can write a batch file that will emulate 'whereis' command as in Windows Vista. Below is a batch script which searches specified file on system drive. This script is slower as it searches entire system drive for file unlike whereis command in Vista and lists every instance of file with it's attributes.

Write 'whereis' emulator:

          Open a notepad, copy and paste the presented whereis.bat code in it. save it as 'whereis.bat'.

whereis.bat Code

@echo off
if not "%~0"=="%~0%~1" goto firsttime
echo help: type 'whereis filename' to run command
echo Don't run whereis on more than one cmd at a time.
exit /b
if "%~1"=="/?" goto help
set filename=%*
echo %filename%>%temp%\file.txt
cd /d %temp%
for /f "tokens=* " %%i in (file.txt) do set filename=%%~i
echo Searching "%filename%" on %systemdrive% drive(System drive).
dir /a:-d /b /s|find /I "%filename%">%temp%\temp2.txt
cd %temp%
for /f "tokens=* " %%i in (temp2.txt) do if /I "%filename%"=="%%~nxi" attrib "%%~i"
for /f "tokens=* " %%i in (temp1.txt) do cd /d "%%~i"
del %temp%\temp1.txt
del %temp%\temp2.txt

Possible attributes for a file:

R-Read only

How To Use:

          Open the folder where you saved the 'whereis.bat', right click on the file and Send To-> Command Prompt Here (We have seen how to add 'Command Prompt Here' option to 'Send To' in previous post. See 'Command Prompt Here'). It will open the command prompt at parent folder.Type

whereis.bat file.ext


    H c:\file.ext
A   H c:\dir\file.ext

Output Explaination:

          Above output tells that file.exe is present in

  1. C: drive and is hidden.
  2. C:\dir and is archived and hidden.

Useful Modifications:

          You can modify this script to search a file on other drive. Just place the drive letter before cd\ command in bat file. The file also provides help regarding uses if you type whereis /?.

Related Posts:
Leave a comment

No comments:

Post a Comment