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.
Asked
Active
Viewed 2,646 times
10
-
Is [_Batch script, check if file exists, then execute_](http://serverfault.com/questions/819854/batch-script-check-if-file-exists-then-execute) the same question? Ask rather at [StackOverflow](http://stackoverflow.com/questions/tagged/batch-file). – JosefZ Dec 12 '16 at 16:31
2 Answers
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
- 2
- 7
10
setlocal enabledelayedexpansion enableextensions
set LIST=
for %%x in (%baseDir%\*) do set LIST=!LIST! %%x
set LIST=%LIST:~1%

James Connigan
- 137
- 2
- 13
-
Code without explanation is not very useful. Please edit your answer to explain what the code does. – kasperd Dec 31 '16 at 00:10