Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

batch-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?

like image 226
u123 Avatar asked Jan 08 '11 17:01

u123


1 Answers

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
like image 180
Bruno Brant Avatar answered Sep 22 '22 00:09

Bruno Brant