Reputation: 57
I've been looking around the Internet and finding bits of pieces of what I need but I figured coming here is my best bet.
I'm creating a project right now and it requires a batch file to locate a specific file on my system (Yes its unique) to be ran.
Say the file I have in mind is named helloWorld.vbs, I want that opened and its located on my Desktop which is C:\Users\Myself\Desktop
What would be a line of code I could input into the CLI to
A.) Find the specified file no matter where it actually is in my system, it could be in documents or anywhere the user places it.
B.) Running the actual program and not just listing the directory of where its currently at.
C.) Staying within the specified directory.
Upvotes: 0
Views: 51
Reputation: 56180
A1.) change to Users HomeDir: (cd C:\
to search the whole drive - but this would take some time...)
cd %userprofile%
A2.) find the file and it's location
for /f "delims=" %%i in ('dir /s /b "my filename.exe"') do (
set "file=%%~nxi"
set "filepath=%%dpi"
)
echo found %file% in %filepath%
B.) goto the directory and execute the file
cd %filepath%
"%file%"
REM or start or call (depends on your needs)
C.) stay in the directory (nothing to do)
Upvotes: 1