Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fs.rename = fs.move
- local function digits(str)
- local a, b
- local c, d
- for i = 0, #str do
- c, d = a, b
- a, b = str:find(string.rep("%d", i))
- if not a then
- break
- end
- end
- return c, d
- end
- local function split(str)
- local a, b = digits(str)
- local prefix = str:sub(1, a - 1)
- local digits = tonumber(str:sub(a, b))
- local zerocount = (b - a + 1) - #tostring(digits)
- local suffix = str:sub(b + 1, #str)
- return prefix, digits, zerocount, suffix
- end
- local function add(str, val)
- local data = {split(str)}
- data[2] = tostring(data[2] + val)
- local name = data[1]..string.rep("0", data[3])..data[2]..data[4]
- return name
- end
- function renameFiles(val, loc)
- local loc = loc or "/rename"
- if not fs.exists(loc) then
- error("Location folder ("..loc..") doesn't exists", 2)
- for _, oldName in pairs(fs.list(loc)) do
- if not fs.isDir(oldName) then
- local newName = add(name, val)
- fs.rename(oldName, newName)
- print("Renamed "..oldName.." to "..newName..".")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment