I am working on a system that does not support lua File System Library. So i have to make my own directory iterator that gives me list of files with full path of particular format.
The system has a API the we can set for Directory path and another API to get list of file in that directory in lua table format.
The API:FileSetDir() sets the Directory to get file list. The API:FileList() gives table of list of file from the directory we have set using API:FileSetDir().
For example consider the following directory structure.
Movies/3d Movies/Avatar/Avatar.mp4
Movies/3d Movies/Avengers/Avengers.mkv
Movies/3d Movies/ironman.mp4
Movies/Horor/Ring/Ring.avi
Movies/Horor/A Nightmare On Elm Street/A Nightmare On Elm Street.iso
Movies/Barfi.mkv
My Code..
RootDirList1 = {}
RootDirList = {}
finalpath={}
function SetDIR(v)
if v=="" then
RootDir = '/mnt/media/net/192.168.1.40_usbshare1/Movies/'
else
RootDir = '/mnt/media/net/192.168.1.40_usbshare1/Movies/'..v
end
API:FileSetDir (RootDir)
RootDirList1 = API:FileList ()
CheckDirectory()
end
function CheckDirectory()
for i,v in pairs(RootDirList1) do
local RootDir = '/mnt/media/net/192.168.1.40_usbshare1/Movies/'..v
API:FileSetDir (RootDir)
local RootDirList = API:FileList ()
if RootDirList == nil then
print(v)
print("Not Directory")
if string.find(v,"%.mkv$") or string.find(v,"%.mp4$") then
finalpath[#finalpath+1] =RootDir.."/"..t
print(RootDir.."/"..t)
end
else
CheckDirectory(v)
end
end
end
SetDIR("")
The code gives me error with "Stack Overflow".
The SetDIR sets the Directory with API:FileSetDir(RootDir) and get the file list in RootDirList1 table. then i am calling function CheckDirectory() here i am running a for loop over RootDirList1 table if the table entry is file the it will be stored in to finalpath table. if table entry is Directory then it calls SetDIR to get list of file in that directory.
I know my approach is wrong to make this work any bright idea will be greatly appreciated.
CheckDirectory(v)mean?CheckDirectorydoes not have arguments! - Egor Skriptunoff