u123
u123

Reputation: 16329

Check that folder contains files with specific extension (windows bat file)

Hi I am trying to create a windows bat file that checks if a folder contains files of a specify extension and the runs some basic command. Something like:

set inputFolder=%1

if [%inputFolder%.containsExtension("class")] goto exists

goto end
:exists

:end

but how do I check the extension of the files in inputFolder?

Upvotes: 5

Views: 11340

Answers (1)

Bruno Brant
Bruno Brant

Reputation: 8564

The simplest way to do this is using a dir command and checking the ERRORLEVEL environment variable using EXISTS directive.

set inputFolder=%1
set extension=%2

IF EXIST %inputFolder%\*.%extension% GOTO exists

goto end

:exists

echo exists

:end

Upvotes: 9

Related Questions