Anonymous user
Extract file extension: Difference between revisions
→{{header|zkl}}: update
(→{{header|ALGOL W}}: Changed test cases to be those of the revised tas.) |
(→{{header|zkl}}: update) |
||
Line 1,119:
=={{header|zkl}}==
The File object has a method splitFileName that does just that, returning a list of the parts. The method knows about the OS it was compiled on (Unix, Windows).
<lang zkl>valid:=Walker.chain(".",["a".."z"],["A".."Z"],["0".."9")).sink(String).walk();
foreach nm in (T("http://example.com/download.tar.gz","CharacterModel.3DS",
".desktop","document",
"document.txt_backup","/etc/pam.d/login")){
if(ext-valid) ext="";
println("%35s : %s".fmt(nm,ext));
}</lang>▼
{{out}}
Note: on Unix, .desktop is a hidden file, not an extension.
<pre>
http://example.com/download.tar.gz : .gz
CharacterModel.3DS : .3DS
.desktop :
document :
document.txt_backup :
/etc/pam.d/login :
</pre>
▲ ext:=File.splitFileName(fileName)[-1];
▲}</lang>
|