View Single Post
Old 03-15-2019, 08:42 AM   #314
juliansader
Human being with feelings
 
Join Date: Jul 2009
Posts: 3,714
Default

Quote:
Originally Posted by reapero View Post
Or should i already consider using conditionals based on OS? Pretty lost here
There are two conditionals that you should consider:

1) If only one file was selected, the folder is not returned separately, and the entire path with file name is returned as a single string.

2) On macOS, the folder is sometimes (always?) not returned separately. (BTW, I'm not sure why -- is it a bug, or can a user select files from more than one folder?)


Quote:
So, is there any possible way for me to end up with the same table i did on the PC? This:
Sure, simply extract the folder path, store it in t[1] and remove it from all the other entries:

Code:
t = {}
for file in list:gmatch("[^\0]*") do
    t[#t+1] = file
end
if #t > 1 and t[1] == "" then -- macOS multiple files?
    t[1] = t[2]:match("^.*/") or "" -- folder path
    for i = 2, #t do
        local filename = t[i]:match("[^/]+$")
        if t[i] == t[1] .. filename then -- check that each entry consists of folder..filename
            t[i] = filename
        else
            -- Error: not all files from same folder!
        end
    end
end
juliansader is offline   Reply With Quote