File extension is in extensions list: Difference between revisions
Content deleted Content added
Drkameleon (talk | contribs) No edit summary |
Undo revision 324498 by Drkameleon (talk) AWK solution taken out by mistake when editing Arturo solution. |
||
Line 186: | Line 186: | ||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
⚫ | |||
⚫ | |||
in? extract.extension lower file |
|||
fileExtensions |
|||
] |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
lowercased: map fileExtensions => lowercase |
|||
contains lowercased [lowercase|replace [pathExtension file] "." ""] |
|||
} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre>MyData.a## => hasExtension |
<pre>MyData.a## => hasExtension: true |
||
MyData.tar.Gz => hasExtension |
MyData.tar.Gz => hasExtension: true |
||
MyData.gzip => hasExtension |
MyData.gzip => hasExtension: false |
||
MyData.7z.backup => hasExtension |
MyData.7z.backup => hasExtension: false |
||
MyData... => hasExtension |
MyData... => hasExtension: false |
||
MyData => hasExtension |
MyData => hasExtension: false</pre> |
||
=={{header|AWK}}== |
|||
This solution meets the extended criteria stated in the problem. |
|||
<lang AWK> |
|||
# syntax: GAWK -f FILE_EXTENSION_IS_IN_EXTENSIONS_LIST.AWK |
|||
BEGIN { |
|||
n = split("zip,rar,7z,gz,archive,A##,tar.bz2", arr, ",") |
|||
for (i=1; i<=n; i++) { |
|||
ext_arr[tolower(arr[i])] = "" |
|||
} |
|||
filenames = "MyData.a##,MyData.tar.Gz,MyData.gzip,MyData.7z.backup,MyData...,MyData,MyData_v1.0.tar.bz2,MyData_v1.0.bz2" |
|||
n = split(filenames, fn_arr, ",") |
|||
⚫ | |||
for (i=1; i<=n; i++) { |
|||
ext_found = "" |
|||
for (ext in ext_arr) { |
|||
if (tolower(fn_arr[i]) ~ (".*\\." ext "$")) { |
|||
ext_found = ext |
|||
break |
|||
} |
|||
} |
|||
ans = (ext_found == "") ? "is not in list" : ("is in list: " ext_found) |
|||
printf("%s extension %s\n", fn_arr[i], ans) |
|||
} |
|||
exit(0) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
MyData.a## extension is in list: a## |
|||
MyData.tar.Gz extension is in list: gz |
|||
MyData.gzip extension is not in list |
|||
MyData.7z.backup extension is not in list |
|||
MyData... extension is not in list |
|||
MyData extension is not in list |
|||
MyData_v1.0.tar.bz2 extension is in list: tar.bz2 |
|||
MyData_v1.0.bz2 extension is not in list |
|||
</pre> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |