#! lua
-- Nocomma
-- G.C.Wraith (07/06/2020)
local dir in riscos
local sep, thedir = ".", arg[1]
thedir = thedir:gsub("%.[^%.]+$","") -- ambient directory
local extpat = ",([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])$"
local dirftype = 4096
local appftype = 2*dirftype
local settype = "settype %s %03x"
local rename = "rename %s %s"
local j = "%s.%s"

local cmd = { }

local scan
scan = \ (d)
       for leaf, ftype in dir (d) do
          local obj = j:format (d, leaf)
          if ftype == dirftype or ftype == appftype then scan (obj) end
          local rt = leaf:match (extpat)
          if rt then
             cmd[1 + #cmd] = settype:format (obj, tonumber (rt, 16))
             cmd[1 + #cmd] = rename:format (obj, obj:gsub (extpat, ""))
          end -- if
      end -- for
    end -- function

scan (thedir)

local obey = \ (cmd)
       local execute in os
       for _,command in ipairs(cmd) do
         execute(command)
       end -- for
       end -- function

obey (cmd)



