
function Execute(aCommand)
  local i, t, popen = 0, {}, io.popen
  for filename in popen(aCommand):lines() do
    i = i + 1
    t[i] = filename
  end
  return t
end

--local cmd = 'dir /b *.jpg'
--local cmd = 'ls -1 *.jpg'
--local cmd = 'ls -1 *.c'

--local ext = 'pas'
--local cmd = 'ls -1 -S -r *.' .. ext

local cmd = 'ls -1 *.cbl'
 
local t = Execute(cmd)

for i = 1, #t do
  print(t[i])
  --print(os.rename(t[i], string.format('%0.2d.' .. ext, i)))
  --if string.find(t[i], ' ') then
  --  local newname = string.gsub(t[i], ' ', '-')
  --  os.rename(t[i], newname) 
  --end
  local newname = string.sub(t[i], 1, -4) .. 'cob'
  print(newname)
  os.rename(t[i], newname)
end
