Jump to content

File extension is in extensions list: Difference between revisions

→‎{{header|Java}}: Add simpler, less-robust version
(→‎{{header|Perl 6}}: handle extensions the Unix Way, agnostically)
(→‎{{header|Java}}: Add simpler, less-robust version)
Line 82:
test: true
a/b/c\d/foo: true</pre>
===Using FileNameExtensionFilter===
{{works with|Java|6+}}
This version is the same as the main version only replace the definition for <code>extIsIn</code> with:
<lang java5>public static boolean extIsInFF(String test, String... exts){
for(int i = 0; i < exts.length; i++){
exts[i] = exts[i].replaceAll("\\.", "");
}
return (new FileNameExtensionFilter("extension test", exts)).accept(new File(test));
}</lang>
It would be one line if not for the dot requirement. <code>FileNameExtensionFilter</code> requires that the extensions have no dots. It also requires that the extensions contain characters (i.e. not the empty string) so that test would need to be removed.
 
=={{header|Perl 6}}==
<lang perl6>sub ext-in-list(@ext,@files) {
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.