File extension is in extensions list

From Rosetta Code
Revision as of 16:47, 11 August 2014 by rosettacode>Isrunt
Task
File extension is in extensions list
You are encouraged to solve this task according to the task description, using any language you may know.

Given a file name and a list of extensions (including the dot), tell whether the file's extension is in the extensions list. The check should be case insensitive.

Python

<lang Python> import os

def isExt(filename, extensions):

   return os.path.splitext(filename.lower())[-1] in [e.lower() for e in extensions]

</lang>


Scala

<lang Scala> def isExt(fileName: String, extensions: List[String]): Boolean = {

   extensions.map { _.toLowerCase }.exists { fileName.toLowerCase endsWith _ }

} </lang>