I am new to lua to trying to understand and put pieces to together and looking out for some help. I have gone through the existing articles on lua file looping but unable to get the desired output.
Question - I have a folder with files, Folder path - "D:\Test_Files\Outbound\Client\final"
Files in the folder with extension - .txt
Trying to :
- Get the count of files in the folder(in this case "final" folder).
Read every file, building a loop something similar to this:
list = {} for i=0,(#Totalfilecount) do local fr = io.open('D:\Test_Files\Outbound\Client\final\'..filename.,'rb') local f = fr.read('*.txt') Customfunction(f) -- Passing file content to customfunction to apply business logic. end
Questions :
- How to get file count from a directory?
- How to read the directory to check if the files with "*.txt" exist?
- How to use table list to store each file name and read through the loop?
- How to read each file via loop and pass the value to function "Customfunction(f)"?
Code is expected to run on windows. Please share suggestions in pure lua without using external file system functions such as 'lfs' as we do not like to import external functions.
Any Suggestions/help will be greatly appreciated!