Page 1 of 1

Simple way for get dirs and files from user android filesystem

Posted: Sun May 31, 2020 1:03 am
by cristoferfb
Hi, I want to access to all the user android filesystem (commonly /storage/emulated/0) I notice a function getDirectoryItems() but this not work:

Code: Select all

love.filesystem.getDirectoryItems("/storage/emulated/0/") 
(I have enable storage permissions)

Re: Simple way for get dirs and files from user android filesystem

Posted: Sun May 31, 2020 9:24 am
by zorg
Löve can't access anything other than the save directory and where main.lua is, whether the latter is a folder or inside a .love file (zip archive), and potentially the folder where the .love file is, if you can mount it (works on windows at least, idk about other OS-es)

There have been attempts at libraries that would allow arbitrary locations and absolute paths; you can try this, but not sure if it'll work on android or not: https://github.com/megagrump/nativefs

Re: Simple way for get dirs and files from user android filesystem

Posted: Tue Jun 02, 2020 3:27 am
by cristoferfb
zorg wrote: Sun May 31, 2020 9:24 am Löve can't access anything other than the save directory and where main.lua is, whether the latter is a folder or inside a .love file (zip archive), and potentially the folder where the .love file is, if you can mount it (works on windows at least, idk about other OS-es)

There have been attempts at libraries that would allow arbitrary locations and absolute paths; you can try this, but not sure if it'll work on android or not: https://github.com/megagrump/nativefs
I am actually using the unix terminal of the android device.

Code: Select all

local dir = io.popen ("ls "..someDir)
io.input(dir)
I dont know if this is portable to any other android device I think yes. I will take a look to how works that library u mentioned.

Re: Simple way for get dirs and files from user android filesystem

Posted: Tue Jun 02, 2020 8:57 am
by zorg
lua io might fail with specific characters in paths & filenames; what i linked shouldn"t.

Re: Simple way for get dirs and files from user android filesystem

Posted: Mon Jun 22, 2020 6:16 am
by AuahDark
cristoferfb wrote: Tue Jun 02, 2020 3:27 am I am actually using the unix terminal of the android device.

Code: Select all

local dir = io.popen ("ls "..someDir)
io.input(dir)
I dont know if this is portable to any other android device I think yes. I will take a look to how works that library u mentioned.
That works, but you have to request external storage permission. If the user denies it, then there's nothing you can do.
zorg wrote: Tue Jun 02, 2020 8:57 am lua io might fail with specific characters in paths & filenames; what i linked shouldn"t.
That only applies to Windows. io.open in Android (Linux) is UTF-8, so there's no problem with it.