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

-- local files = Execute('dir /b *.lxf')
-- local files = Execute('for %x in (*.lxf) do @echo %~sx')
local files = Execute('dir /b *.md')

for i = 1, #files do
  print(files[i])
  -- print(os.rename(files[i], string.format("%0.3d.lxf", i)))
  local titre, classe = string.match(files[i], '(%w+)%-([^-]+%d)%.md')
  if titre then
    classe = string.sub(classe, -2, -1)
    local newname = string.format('%s-%s.md', classe, titre)
    print(newname)
    os.rename(files[i], newname)
  end
end

-- os.execute("pause")
