File extension is in extensions list: Difference between revisions

→‎{{header|REXX}}: added REXX code to handle a path in the filename, also to handle a filename with multiple periods at the tail end.
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:
 
=={{header|REXX}}==
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)*/
extentions='.bat .cmd .com .inidat .txt'dll .exe /*this.ini would.jpg be.jpeg the.log complete.sys list*/.txt'
say 'Filename ' fn "/* has[↑] no extensionabove would be some EXTs."*/
parse arg fn /*get the filename from the C.L. */
fn=strip(fn) /*remove any superfluous blanks. */
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*/
say 'Filename ' fn " has no extension."
p=lastpos('.',afn) /*find the last position of a exitdot*/
if p==0 | p==length(afn) then do /*no dot or dot is at end of endname*/
ft=substr(fn,p) /*pickoff the fileType (fileExt) 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*/
if wordpos(ft,extentions)==0 then _='an unknown'