-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileChooser.lua
38 lines (36 loc) · 1.04 KB
/
FileChooser.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
local Path = require('jls.io.Path')
local File = require('jls.io.File')
local function listFiles(value, callback)
if type(callback) ~= 'function' then
return
end
local dir = File:new(value or '.'):getAbsoluteFile()
local files = dir:listFiles()
local parent = dir:getParent()
if files then
local list = {}
if parent then
table.insert(list, {
name = '..',
isDirectory = true,
length = 0,
lastModified = dir:lastModified(),
})
end
for _, file in ipairs(files) do
table.insert(list, {
name = file:getName(),
isDirectory = file:isDirectory(),
length = file:length(),
lastModified = file:lastModified(),
})
end
local path = Path.normalizePath(dir:getPath())
--print('listFiles('..tostring(value)..') "'..tostring(path)..'" found '..tostring(#list)..' entries, parent: "'..tostring(parent)..'"')
table.insert(list, 1, path)
callback(nil, list)
end
end
return {
listFiles = listFiles
}