Quizzed
Quizzed

Reputation: 173

Check if variable is a text file

How would I go about checking if a variable is a .txt file?

My code isn't working:

if /I "%ph2file%" NEQ "*.txt" echo This file is not a .txt file.

Upvotes: 0

Views: 154

Answers (1)

Stephan
Stephan

Reputation: 56238

the "quick and dirty" way (check last four characters):

if /i "%ph2file:~-4%" neq ".txt" echo no .txt file

the "clean" way (check the extension):

for %a in ("%ph2file%") do echo if "%~xa" neq ".txt" echo no .txt file

Upvotes: 3

Related Questions