OK, I think I have skeleton code to rename IMG_####.jpg files to mmddHHMM.jpg.
So far it's not elegant - every time it's run it will loop through every directory under DCIM. But I can clean that up later... I am using lua libs 0.7 from mattkime's compiliation of scripts by fbonomi and others.
I would love any feedback from expert script writers. Especially about syntax errors, optimizing, and if I might have problems running this on a memory card with ~1000 images. Here's my code:newPicList = disk.filterImageFiles("IMG_")
for index,oldName in ipairs(newPicList) do
fileInfo = os.stat(oldName)
newName = os.date("%m%d%H%M",fileInfo.mtime)
picDir = string.sub(oldName,1,16)
os.rename(oldName,picDir..newName..".jpg")
end
and here is the code for the disk.filterImageFiles function and the disk.getImageList function it depends on:-- returns list of files that contain the provided search string
function disk.filterImageFiles(searchString,directory)
--log.print("disk.filterImageFiles - start")
local imageList, strStart
if(directory == nil) then
imageList = disk.getImageList()
strStart = 17
else
imageList = os.listdir("A/DCIM/"..directory,false)
strStart = 1
end
local count = table.getn(imageList)
--log.print("disk.filterImageFiles - count:",count)
local i = 0
while i ~= count do
i = i + 1
--log.print(imageList[i])
if(string.find(imageList[i],searchString,strStart, true) == nil) then
table.remove(imageList,i)
i = i - 1
count = count - 1
end
end
--log.print("disk.filterImageFiles - end ")
return imageList
end
--[[ Loops through DCIM dirs and creates list of files ]]
--optionally take directory name?
function disk.getImageList()
local imgTable = {}
local dcimList = disk.getImageDirectories()
local dirCount = table.getn(dcimList)
local i = 0
while ( dirCount ~= i) do
i = i + 1
--log.print(dcimList[i].."\n")
local imgDirList = os.listdir(dcimList[i], false)
local imgCount = table.getn(imgDirList)
--log.print("imgCount:"..imgCount)
table.sort(imgDirList)
local a = 0
while (imgCount ~= a) do
a = a + 1
--log.print(dcimList[i].."/"..imgDirList[a])
table.insert(imgTable,dcimList[i].."/"..imgDirList[a])
sleep(1)
end
end
return imgTable
end