Anonymous user
File extension is in extensions list: Difference between revisions
File extension is in extensions list (view source)
Revision as of 20:47, 12 August 2014
, 9 years ago→{{header|REXX}}: added support for blanks in the filename and/or file extension.
(→{{header|Perl 6}}: disallow slash too) |
(→{{header|REXX}}: added support for blanks in the filename and/or file extension.) |
||
Line 112:
:::* 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 (per a list)*/
/*╔════════════════════════════════════════════════════════════════════╗
extensions='.bat .cmd .com .dat .dll .exe .ini .jpg .jpeg .log .sys .txt'▼
║ 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.*/
parse arg fn /*get the filename from the C.L. */
if fn=='' then exit /*No fn specified? Then exit.*/
afn=translate( fn, '/', "\")
afn=
afn=substr(afn,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*/
Line 126 ⟶ 133:
end
ft=substr(afn,p) /*pickoff the fileType (fileExt).*/
say 'ft=' ft
upper ft extensions /*uppercase a couple of REXX vars*/
if wordpos(ft,extensions)==0 then _='an unknown'
|