10

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.

2 Answers2

11

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

Vinny
  • 407
10
setlocal enabledelayedexpansion enableextensions
set LIST=
for %%x in (%baseDir%\*) do set LIST=!LIST! %%x
set LIST=%LIST:~1%
  • Code without explanation is not very useful. Please edit your answer to explain what the code does. – kasperd Dec 31 '16 at 00:10