1.

Solve : Search drive for exe and run if found?

Answer»

Hi I was wondering how to go about making a BATCH file to search the C: for a particular .exe file, and to start it if it is found.
It needs to work nomatter what directory the .exe is in.
Any ideas?@echo off
set av1=%cd:~0,1%
for /f "tokens=1*" %%a in ('dir %av1%:\yourexefile.exe /a /b /s') do start %%a



first line turns echo off
second line sets the drive letter as %av1%
third line searches from drive %av1%:\ for yourexefile.exe , /b for bare format /s to INCLUDE all sub directorys, so if you start in root "%av1%:\" it searches the entire drive , /a includes all hidden files & foldersWorks great apart from one thing. If the directory has a SPACE in it eg. 'Program Files' it comes up with an error saying Windows cannot find 'C:\Program'.
Is there a way to get it to work for directories with spaces by putting QUOTES around the file path or something?Diablo your video scare me you have to add double quotes:

start "%%a"

ypusing double qutoes in start will make it open cmd.exe again with title "%%a"

use this instead

for /f "tokens=1*" %%a in ('findstr /I %au1a% yourfile.exe') do RunDll32.exe shell32.dll,ShellExec_RunDLL "%%a"Cheers

for /f "tokens=1*" %%a in ('dir %av1%:\yourexefile.exe /a /b /s') do RunDll32.exe shell32.dll,ShellExec_RunDLL "%%a"

Works for me



Discussion

No Comment Found