File extension is in extensions list: Difference between revisions

Content added Content deleted
(→‎Tcl: Added implementation)
Line 238: Line 238:
extensions.map { _.toLowerCase }.exists { fileName.toLowerCase endsWith _ }
extensions.map { _.toLowerCase }.exists { fileName.toLowerCase endsWith _ }
}</lang>
}</lang>

=={{header|Tcl}}==
<lang tcl># Note that these are already all in lower case
set exts {".txt" ".gz" ".bat" ".c" ".c++" ".exe" ".pdf"}
set filenames {
text.txt
text.TXT
test.tar.gz
test/test2.exe
test\\test2.exe
test
a/b/c\\d/foo
foo.c
foo.C
foo.C++
foo.c#
foo.zkl
document.pdf
}

foreach name $filenames {
set ext [file extension $name]
if {[string tolower $ext] in $exts} {
puts "'$ext' (of $name) is present"
} else {
puts "'$ext' (of $name) is absent"
}
}</lang>
{{out}}
<pre>
'.txt' (of text.txt) is present
'.TXT' (of text.TXT) is present
'.gz' (of test.tar.gz) is present
'.exe' (of test/test2.exe) is present
'.exe' (of test\test2.exe) is present
'' (of test) is absent
'' (of a/b/c\d/foo) is absent
'.c' (of foo.c) is present
'.C' (of foo.C) is present
'.C++' (of foo.C++) is present
'.c#' (of foo.c#) is absent
'.zkl' (of foo.zkl) is absent
'.pdf' (of document.pdf) is present
</pre>


=={{header|zkl}}==
=={{header|zkl}}==