File extension is in extensions list: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: disallow slash too) |
(→{{header|REXX}}: added support for blanks in the filename and/or file extension.) |
||
Line 112: | Line 112: | ||
:::* handle cases of the filename ending in a period |
:::* handle cases of the filename ending in a period |
||
:::* handle cases of the filename ending in multiple periods |
:::* 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 (per a list)*/ |
<lang rexx>/*REXX program displays if a filename has a known extension (per a list)*/ |
||
/*╔════════════════════════════════════════════════════════════════════╗ |
|||
⚫ | |||
║ The list of extenions below have blanks encoded as 'ff'x. ║ |
|||
║ The extension pointed to has a 'ff'x after the period──────────┐ ║ |
|||
║ (which is used to indicate a true blank, due to │ ║ |
|||
║ REXX's use of blanks in lists as delimitors). │ ║ |
|||
╚══════════════════════════════════════════════════════════════════↓═╝*/ |
|||
⚫ | |||
/* [↑] above would be some EXTs.*/ |
/* [↑] above would be some EXTs.*/ |
||
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. */ |
|||
if fn=='' then exit /*No fn specified? Then exit.*/ |
if fn=='' then exit /*No fn specified? Then exit.*/ |
||
afn=translate(fn,'/',"\") |
afn=translate( fn, '/', "\") /*handle both versions of pathSep*/ |
||
afn= |
afn=translate(afn, 'ff'x, " ") /*··· and also handle true blanks*/ |
||
afn=substr(afn,lastpos('/',afn)+1) /*pick off the filename from path*/ |
|||
p=lastpos('.',afn) /*find the last position of a dot*/ |
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*/ |
if p==0 | p==length(afn) then do /*no dot or dot is at end of name*/ |
||
Line 126: | Line 133: | ||
end |
end |
||
ft=substr(afn,p) /*pickoff the fileType (fileExt).*/ |
ft=substr(afn,p) /*pickoff the fileType (fileExt).*/ |
||
say 'ft=' ft |
|||
upper ft extensions /*uppercase a couple of REXX vars*/ |
upper ft extensions /*uppercase a couple of REXX vars*/ |
||
if wordpos(ft,extensions)==0 then _='an unknown' |
if wordpos(ft,extensions)==0 then _='an unknown' |