File extension is in extensions list: Difference between revisions
Content added Content deleted
(→{{header|zkl}}: mark as "needs updating") |
(→{{header|REXX}}: changed program to reflect new task requirements and examples.) |
||
Line 621: | Line 621: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
{{update|REXX}} |
|||
Programming note: extra code was added to: |
|||
:::* display some error/warning messages |
|||
:::* handle the case of the filename having a ''path'' |
|||
:::* handle the case of different types of ''path'' separators |
|||
:::* handle the case of the filename having no file extension |
|||
:::* handle cases of the filename ending in a period |
|||
:::* handle cases of the filename ending in multiple periods |
|||
:::* handle cases of blanks in the filename and/or extension |
|||
<lang rexx>/*REXX program displays if a filename has a known extension (as per a list of EXTs).*/ |
<lang rexx>/*REXX program displays if a filename has a known extension (as per a list of EXTs).*/ |
||
$= 'zip rar 7z gz archive A## tar.bz2'; upper $ /*a list of "allowable" file extensions*/ |
|||
/*╔═════════════════════════════════════════════════════════════════════╗ |
|||
parse arg fn /*obtain optional argument from the CL.*/ |
|||
║ The list of extensions below have blanks encoded as 'ff'x. ║ |
|||
⚫ | |||
║ The extension pointed to has a 'ff'x after the period ───►──┐ ║ |
|||
if fn\='' then @.1 = strip(fn) /*A filename specified? Then use it. */ |
|||
else do; @.1 = "MyData.a##" /* else use list*/ |
|||
⚫ | |||
╚═══════════════════════════════════════════════════════════════↓═════╝*/ |
|||
@.3 = "MyData.gzip" |
|||
extensions= '.bat .cmd .com .dat .dll .exe .ini .jpg .jpeg .log .txt . ys' |
|||
@.4 = "MyData.7z.backup" |
|||
@.5 = "MyData..." |
|||
@.6 = "MyData" |
|||
@.7 = "MyData_v1.0.tar.bz2" |
|||
@.8 = "MyData_v1.0.bz2" |
|||
end |
|||
afn=substr(afn, lastpos('/', afn) +1) /*pick off the filename from the path. */ |
|||
#=words($) |
|||
⚫ | |||
do j=1 while @.j\=='' /*traipse through @ list of file exts.*/ |
|||
file=@.j; upper file /*get a filename; and then uppercase it*/ |
|||
do k=1 for # /*search $ list to see if ext is in it.*/ |
|||
x=. || word($, k); L=length(x) /*construct file extension; get length.*/ |
|||
if right(file, L)==x then leave /*Does file has an allowable extension?*/ |
|||
end /*k*/ |
|||
say 'ft=' ft |
|||
say right(@.j, 30) ' ' word("false true", 1 + (k<=#) ) /*nay or yea.*/ |
|||
⚫ | |||
if wordpos(ft,extensions)==0 then _='an unknown' |
|||
{{out|output}} |
|||
⚫ | |||
<pre> |
|||
⚫ | |||
MyData.a## true |
|||
MyData.tar.Gz true |
|||
MyData.gzip false |
|||
MyData.7z.backup false |
|||
MyData... false |
|||
MyData false |
|||
MyData_v1.0.tar.bz2 true |
|||
MyData_v1.0.bz2 false |
|||
</pre> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |