Splitting Filenames


A couple of tedious tasks, breaking a complete filename into separate folder/file parts, and determining the filename extension...

 ∇ z←{a}SplitName w;⎕IO;⎕ML
      ⍝ Split filename into folder and file
      ⎕IO ⎕ML←0 3
      :If 0=⎕NC'a'
          a←'\'
      :EndIf
      z←{∊¨((¯1↓⍵),¨↑a)(¯1↑⍵)}(~w∊a)⊂w
    ∇


Sample usage:

SplitName 'c:\dick\temp\aaa.bbb.txt'

and (expressed as a Dyalog d-fn)...

FindExtension←{⎕IO ⎕ML←0 3
      ⍝ Find filename extension
          ∊¯1↑(~⍵∊'.')⊂⍵}

Sample usage:

FindExtension 'c:\dick\temp\aaa.bbb.txt'

Notes:
Page created 13 February 2009.
Copyright © Dogon Research 2009.