Check for file by wildcard and store as variable in batch file [closed]

I am looking for a way to check a specified folder for a file. I will not have the complete file name, so I will have to use wildcards. After finding the file, I want to store the filename as a variable.


Doesn't directly answer your question about a batch file but this would work easily in a PowerShell script:

$validFile = Test-Path "C:\path\to\your\file"
if ($validFile -eq 'True') {
    $path = C:\path\to\your\file
}

And now you have your file name stored in a variable


setlocal enabledelayedexpansion enableextensions
set LIST=
for %%x in (%baseDir%\*) do set LIST=!LIST! %%x
set LIST=%LIST:~1%