initial commit
This commit is contained in:
commit
0a862c499d
6 changed files with 151 additions and 0 deletions
55
lowercase.lua
Executable file
55
lowercase.lua
Executable file
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/env lua
|
||||
require('os')
|
||||
require('lfs')
|
||||
|
||||
function lowercase(basename, basedir)
|
||||
if basedir == nil then
|
||||
basedir = ''
|
||||
end
|
||||
local lowercased = string.lower(basename)
|
||||
local path_orig = basedir .. basename
|
||||
local path_new = basedir .. lowercased
|
||||
if path_orig == path_new then
|
||||
print(path_orig .. ' is already lowercase!')
|
||||
return 1
|
||||
else
|
||||
print('Renaming: ' .. path_orig .. ' -> ' .. path_new)
|
||||
os.rename(path_orig,path_new)
|
||||
end
|
||||
end
|
||||
|
||||
function is_dir(name)
|
||||
local ftype = lfs.symlinkattributes(name, "mode")
|
||||
if ftype == "directory" then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
function find_and_rename(path)
|
||||
for basename in lfs.dir(path) do
|
||||
if basename ~= "." and basename ~= ".." then
|
||||
local basedir = path .. '/'
|
||||
local filename = basedir .. basename
|
||||
if is_dir(filename) then
|
||||
find_and_rename(filename)
|
||||
end
|
||||
lowercase(basename, basedir)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function test_and_execute(dir)
|
||||
if is_dir(dir) then
|
||||
find_and_rename(dir)
|
||||
lowercase(dir)
|
||||
else
|
||||
print(dir .. ' is not a directory or does not exist!')
|
||||
end
|
||||
end
|
||||
local i = 1
|
||||
while arg[i] do
|
||||
test_and_execute(arg[i])
|
||||
i = i + 1
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue