mirror of
https://codeberg.org/1414codeforge/lua-osx.git
synced 2025-01-22 23:21:31 +01:00
[examples/rename] Improve comments.
This commit is contained in:
parent
ba26f107da
commit
ca5ea0085c
@ -21,6 +21,7 @@ local pattern = assert(select(1, ...), "Missing filename pattern argument")
|
||||
local repl = assert(select(2, ...), "Missing filename replacement argument")
|
||||
local path = select(3, ...) or "."
|
||||
|
||||
-- Rename en-masse
|
||||
for filename in dir(path) do
|
||||
local newfilename = filename:gsub(pattern, repl, 1)
|
||||
|
||||
@ -28,14 +29,17 @@ for filename in dir(path) do
|
||||
local from = path..sep..filename
|
||||
local to = path..sep..newfilename
|
||||
|
||||
-- Refuse to overwrite files
|
||||
local buf, err, code = osx.stat(to)
|
||||
if buf then
|
||||
error(filename..": File '"..to.."' exists, refusing to overwrite.")
|
||||
end
|
||||
if code ~= ENOENT then
|
||||
-- Anything but "file does not exist" is dangerous, so bail out
|
||||
error(err)
|
||||
end
|
||||
|
||||
-- Print a nice message and rename things
|
||||
write(from, ' -> ', to)
|
||||
assert(osx.rename(filename, newfilename))
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user