This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Read CSV file from LM/SL FTP device folder and put data to groups
#2
This can be used a starting point:
Code:
-- FTP directory absolute path
dir = '/home/ftp/'
-- get file list
files = io.ls(dir)

-- go through all files
for _, file in ipairs(files) do
  -- full file path
  path = dir .. '/' .. file
  -- read file data
  data = io.readfile(path)
  -- split into lines
  lines = data:split('\n')
  -- remove CSV header
  table.remove(lines, 1)

  -- go through all lines
  for _, line in ipairs(lines) do
    -- split each line into separate values
    values = line:trim():split(',')
    log(values)
  end

  -- remove file
  os.remove(path)
end
Reply


Messages In This Thread
RE: Read CSV file from LM/SL FTP device folder and put data to groups - by admin - 07.05.2021, 14:43

Forum Jump: