View Single Post
Old 12-12-2018, 10:06 AM   #132
Meo-Ada Mespotine
Human being with feelings
 
Meo-Ada Mespotine's Avatar
 
Join Date: May 2017
Location: Leipzig
Posts: 6,630
Default

For the JS_Dialog_BrowseForOpenFiles-function, you can use the following code, to separate the filenames and path:

Code:
function SplitFilenameStringAtNULLBytes(splitstring)
--  if type(splitstring)~=nil 
  -- add a NULL-Byte at the end, helps us finding the end of the string later
  splitstring=splitstring.."\0"
  local count=0
  local filenames={}
  local temp, offset
  
  -- let's get the path
  local path, offset=splitstring:match("(.-)()\0")
  splitstring=splitstring:sub(offset+1,-1)
  
  -- let's get the filenames
  while splitstring~=nil do
    -- find the next filename
    temp,offset=splitstring:match("(.-)()\0")
    
    if temp~=nil then 
      -- if the next filename isn't nil, then add it fo filenames-array and count+1
      count=count+1 
      filenames[count]=temp
      splitstring=splitstring:sub(offset+1,-1)
    else 
      -- if filename is nil, the string is probably finished splitting
      break 
    end
  end
  return count, path, filenames
end
__________________
Use you/she/her.Ultraschall-Api Lua Api4Reaper - Donate, if you wish

On vacation for the time being...
Meo-Ada Mespotine is offline   Reply With Quote