File extension is in extensions list: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added a programming note.) |
(→{{header|REXX}}: added REXX code to handle a path in the filename, also to handle a filename with multiple periods at the tail end.) |
||
Line 35: | Line 35: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Programming note: extra code was added to display some error/warning messages. |
Programming note: extra code was added to display some error/warning messages, and also to handle the case of the filename having a ''path''. |
||
<lang rexx>/*REXX program displays if a filename has a known extension (per a list)*/ |
<lang rexx>/*REXX program displays if a filename has a known extension (per a list)*/ |
||
extentions='.bat .cmd .com . |
extentions='.bat .cmd .com .dat .dll .exe .ini .jpg .jpeg .log .sys .txt' |
||
⚫ | |||
parse arg fn /*get the filename from the C.L. */ |
parse arg fn /*get the filename from the C.L. */ |
||
fn=strip(fn) /*remove any superfluous blanks. */ |
fn=strip(fn) /*remove any superfluous blanks. */ |
||
if fn=='' then exit /*No fn specified? Then exit.*/ |
if fn=='' then exit /*No fn specified? Then exit.*/ |
||
afn=translate(fn,'/',"\") /*handle both versions of pathSep*/ |
|||
p=lastpos('.',fn); if p==0 then do |
|||
afn=substr(fn,lastpos('/',afn)+1) /*pick off the filename from path*/ |
|||
⚫ | |||
p=lastpos('.',afn) /*find the last position of a dot*/ |
|||
if p==0 | p==length(afn) then do /*no dot or dot is at end of name*/ |
|||
say 'Filename ' fn " has no extension." |
|||
exit |
|||
end |
|||
ft=substr(afn,p) /*pickoff the fileType (fileExt).*/ |
|||
upper ft extentions /*uppercase a couple of REXX vars*/ |
upper ft extentions /*uppercase a couple of REXX vars*/ |
||
if wordpos(ft,extentions)==0 then _='an unknown' |
if wordpos(ft,extentions)==0 then _='an unknown' |