Extract file extension: Difference between revisions

Content added Content deleted
(added Factor)
Line 490: Line 490:
document.txt_backup ->
document.txt_backup ->
/etc/pam.d/login ->
/etc/pam.d/login ->
</pre>

=={{header|Factor}}==
Factor's <tt>file-extension</tt> word allows symbols to be in the extension and omits the dot from its output.
<lang factor>USING: assocs formatting kernel io io.pathnames math qw
sequences ;
IN: rosetta-code.file-extension

qw{
http://example.com/download.tar.gz
CharacterModel.3DS
.desktop
document
document.txt_backup
/etc/pam.d/login
}

dup [ file-extension ] map zip
"Path" "| Extension" "%-35s%s\n" printf
47 [ "-" write ] times nl
[ "%-35s| %s\n" vprintf ] each</lang>
{{out}}
<pre>
Path | Extension
-----------------------------------------------
http://example.com/download.tar.gz | gz
CharacterModel.3DS | 3DS
.desktop | desktop
document |
document.txt_backup | txt_backup
/etc/pam.d/login |
</pre>
</pre>