Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Essentially, I need to create a BATCH file that takes user input and runs the sp

ID: 3850699 • Letter: E

Question

Essentially, I need to create a BATCH file that takes user input and runs the specific file the user inputed. However, I want the script to also search the computer for the file instead of the user having to write the entire directory location.

Here is what I have so far:

echo off
title Windows Updater
:: This file runs several windows updates and then reboots the computer

:Ask
echo Do you have an exe you wish to run?(Y/N)
set INPUT=
set /P answer=Type input: %=%
If /I "%answer%"=="y" goto yes
If /I "%answer%"=="n" goto no

:yes
set /P source=Enter directory of file:
start %source%
pause

echo Do you have another exe file you wish to run?(Y/N)
set INPUT=
set /P answer=Type input: %=%
If /I "%answer%"=="y" goto yes
If /I "%answer%"=="n" goto no

:no
echo the computer will now shut down
:: shutdown.exe /r /t 00

The file does what's it's supposed to, given the directory it runs a file the user inputed. However, how can I edit it so that it finds the file without the user giving the directory location (only the name of the file)?

Explanation / Answer

If the file you searched for was found it will set the variable %p% to the full path of the file including name and extension.

If you just want the path (as in the folder path without the file) then use set p=%%~dpa instead.

If there is more than 1 file with the same name then the variable will be set to the last one found. Also the script after the for loop line isn't really necessary, just to show you if it found anything

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote