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

Possible attributes for a file:

A-Archive
H-Hidden
S-System
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

Output:

    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


Command Prompt Here

          Adding 'Command Prompt Here' link in the right click context menu in Windows XP facilitates opening 'command prompt' at desired folder.

How To Add 'Command Prompt Here' option:
          Open a notepad. Copy and paste the presented cmdph.bat code and save file as cmdph.bat. Now click Start->Run... to open Run dialog box. Type 'sendto' and press ENTER to open 'SendTo' folder. Now create a new shortcut. When it asks for location of file, click browse, locate cmdph.bat, select it and click 'OK'. Click next and type the name for the shortcut. Type this name as 'Command Prompt Here' and click finish. The icon of the shortcut is batfile icon. Note that the shortcut name and icon will appear in right click context menu when you right click on a file or folder and see 'send To' option. You can use any icon of your choice to decorate it.

cmdph.bat code

@echo off
dir /a:d /b %1 1>nul 2>nul
if %errorlevel%==0 goto pass
set parent="%~dp1"
echo %~nx1 is not a directory, redirecting to parent directory...
cd /d %parent%
echo.
goto allowed
:pass
cd /d %1
:allowed
%ComSpec%

With this you can:

  1. Open command prompt at the specified folder with a right click.
  2. Open parent folder by right clicking a file in folder.
Advantages over other tools including Microsoft Powertoy:
  1. It handles folders with '&' in their name where Microsoft Powertoy gives error.
Related Posts:
Leave a comment