anant
anant

Reputation: 69

how to locate and open a file in cmd

How can i search for a program in a directory and open it via cmd? I tried using following command dir /s c:\myprogram.exe but this only shows me the directory in which my program is, but doesn't open it.

Upvotes: 2

Views: 555

Answers (1)

Hackoo
Hackoo

Reputation: 18827

You can try for example this sample batch file to open winrar file :

@echo off
Set "Folder=%ProgramFiles%"
Set "MyFile=winrar.exe"
CD /D "%Folder%"

for /F "delims=" %%F in ('dir /B /S /A:-D "%MyFile%"') do (
    echo "%%~dpF" & pause
    Start "" %MyFile%
)

Or we can use this command Where /? as elzooilogico provided on the comment :

@echo off
Where /R "%programfiles%" winrar.exe
pause
For /F "delims=" %%i in ('Where /R "%programfiles%" winrar.exe') do start "" "%%i"
pause & exit

Upvotes: 1

Related Questions