## [SOLVED] getDirectoryItems() and getInfo()

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
trabitboy
Prole
Posts: 2
Joined: Sun May 12, 2019 2:09 pm

### [SOLVED] getDirectoryItems() and getInfo()

UPDATE:
solved
getDirectoryItems("")
and getInfo("test.lua") returns an empty table , which means existing
can I enrich/ disambiguate the wiki?

Hi,
using 11.2 on win x86-64
I am not sure what I am doing wrong,
trying to list directory items in the savefolder, and doing getInfo () on them;

when I access the files direcly no pb ( save load ), but the 2 above functions give me nothing.
anybody ran into the same problem? did I misunderstand the api ( what should I pass to work in save fld etc ... )
I know it must have worked at some point since liko 12 seems to manage large list of dynamic files /folders in its save directory.

github of the test:
https://github.com/trabitboy/love2dfstest

run with love.exe love2dfstest --console to see output
Last edited by trabitboy on Tue May 14, 2019 4:45 pm, edited 1 time in total.

zorg
Party member
Posts: 2620
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: getDirectoryItems() and getInfo()

Even if you say you solved it, i can't exactly tell what the issue was, nor how it was solved :v

getDirectoryItems should always return a table, even if it's empty if the folder you specified doesn't contain any files, and nothing in the wiki currently says otherwise.

getInfo, however, does tell you that it'll return nil if the given path doesn't exist (and also that specific fields can also be nil)
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

trabitboy
Prole
Posts: 2
Joined: Sun May 12, 2019 2:09 pm

### Re: getDirectoryItems() and getInfo()

thanks for the feedback to improve future reports,
the 2 aspects that were misleading to me:

-spending too much time on linux/cygwin, it was counter intuitive for me to do getDirectoryItems("") instead of getDirectoryItems(".")
it is worth an example in the wiki IMHO

-if the file exists getInfo() returns an empty table, which was counter intuitive to me

pgimeno
Party member
Posts: 1690
Joined: Sun Oct 18, 2015 2:58 pm

### Re: getDirectoryItems() and getInfo()

It doesn't return an empty table, but you have to iterate over the table with pairs(), not with ipairs(), because it doesn't use integer indices.

In the github page you linked, it used ipairs.

mxmlnbndsmnn
Prole
Posts: 16
Joined: Mon Feb 11, 2019 4:17 pm

### similar issue with getDirectoryItems() and getInfo()

Hey, I run into the same or a similar problem (bug? windows thing?)

Code: Select all

local sourcepath = love.filesystem.getSource()
local sourcefiles = love.filesystem.getDirectoryItems(sourcepath)
and

Code: Select all

local savepath = love.filesystem.getSaveDirectory()
local savefiles = love.filesystem.getDirectoryItems(sourcepath)
both give no results (iterating over it with pairs gives nothing, table size is also 0) - yes there ARE files in these folders
I used createDirectory to ensure the save dir exists, but it does not show contents of the folders. The paths, however, are correct (I printed them...)

When I use

Code: Select all

local files = love.filesystem.getDirectoryItems("")
it does give me all the files in the folder (as intended), but the thing is: I do not want to put in all the files initially, instead at runtime. But not via directorydropped, because I need to start the love file (which I turned into an .exe) from a windows task.
In fact, I want the user to have a seperate location to store files to be accessed by my little program.
Maybe you already got the idea: I am creating a custom "screensaver" that uses user images...

Any ideas how to read in images at runtime without using any extra libraries? Or anyone else who found new insights about this problem?

grump
Party member
Posts: 577
Joined: Sat Jul 22, 2017 7:43 pm

### Re: similar issue with getDirectoryItems() and getInfo()

mxmlnbndsmnn wrote:
Sun Jun 02, 2019 8:59 am

Code: Select all

local sourcepath = love.filesystem.getSource()
local sourcefiles = love.filesystem.getDirectoryItems(sourcepath)
and

Code: Select all

local savepath = love.filesystem.getSaveDirectory()
local savefiles = love.filesystem.getDirectoryItems(sourcepath)
You're passing sourcepath to the second getDirectoryItems call, but you probably wanted to pass savepath.

Note that getSource() may return a path that is not a directory, but a love file. I think you want getSourceBaseDirectory() instead, and you can mount() that directory to gain access to it.
Any ideas how to read in images at runtime without using any extra libraries? Or anyone else who found new insights about this problem?
You can mount any path with an ffi trick.

mxmlnbndsmnn
Prole
Posts: 16
Joined: Mon Feb 11, 2019 4:17 pm

### similar issue with getDirectoryItems() and getInfo()

The "sourcepath" was just a copy error in my comment.

Tried the mount() way.

Code: Select all

local success = love.filesystem.mount( "bg", "bgimages", true )
if success then
local savefiles = love.filesystem.getDirectoryItems("bgimages")
for k, fileName in pairs(savefiles) do
local extension = string.sub(fileName, -4)
if tools_isValueInTable(extension, allowedExtensions) then
local img = lg.newImage(fileName)
table.insert(images, { file = img, scaleX = screenW/img:getWidth(), scaleY = screenH/img:getHeight() })
--print(k, fileName)
end
end
else
-- in case we cannot mount the image folder, use one default image that is packed into the exe
local img = lg.newImage("dany_wings_0.jpg")
table.insert(images, { file = img, scaleX = screenW/img:getWidth(), scaleY = screenH/img:getHeight() })
end
Fuse it, run the .exe it only inserts the one image that I packed into the exe for testing, meaning success is false.
When I open the app with love from my editor success is true but it tells me that the images do not exist. The print statement (which is a comment in the above code) prints all images as I expect it to do... But lg.newImage fails with the file does not exist error :c

Maybe Ima try the 2nd option...

Btw I do not really understand why I have to mount folders INSIDE a directory that is KNOWN and ACCESSIBLE by/to love in order to make love able to use it... whut?

zorg
Party member
Posts: 2620
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: [SOLVED] getDirectoryItems() and getInfo()

love.filesystem.mount usually has only two use-cases:
- Open a zip from a known and accessible path; this is most useful for online-distributed patches/dlc/content in general.
- Open a folder, specifically the SourceBase folder if the project is ran on windows and one wants to access files next to the executable file.

So, yeah, you don't need to "mount folders INSIDE a directory that is KNOWN and ACCESSIBLE by/to love", since those ARE accessible already; zips aren't auto-loaded into the PhysFS virtual filesystem though, nor is the executable's own directory automatically added in, so as i said above, those are usually the only cases for using the method.

Also, fused mode has the save folder in a different path on windows (.../<identity> instead of .../LOVE/<identity>), so you might or might not have issues there, like finding files when running unfused but not finding them when running fused, or vice-versa.

Finally, i did create a (fully script-based, not a binary file) library that uses LuaJIT's FFI to access a few PhysFS functions directly, and which also edits love.filesystem.mount (and maybe the VFS paths, optionally) to allow read access on your whole computer. (write access is difficult for multiple reasons, so that's currently missing.) Here's the link to that: https://github.com/zorggn/love-fml
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

grump
Party member
Posts: 577
Joined: Sat Jul 22, 2017 7:43 pm

### Re: [SOLVED] getDirectoryItems() and getInfo()

zorg wrote:
Sun Jun 02, 2019 2:41 pm
Finally, i did create a (fully script-based, not a binary file) library that uses LuaJIT's FFI to access a few PhysFS functions directly, and which also edits love.filesystem.mount (and maybe the VFS paths, optionally) to allow read access on your whole computer. (write access is difficult for multiple reasons, so that's currently missing.) Here's the link to that: https://github.com/zorggn/love-fml
Are PRs welcome?

zorg
Party member
Posts: 2620
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

### Re: [SOLVED] getDirectoryItems() and getInfo()

grump wrote:
Sun Jun 02, 2019 2:58 pm
zorg wrote:
Sun Jun 02, 2019 2:41 pm
Finally, i did create a (fully script-based, not a binary file) library that uses LuaJIT's FFI to access a few PhysFS functions directly, and which also edits love.filesystem.mount (and maybe the VFS paths, optionally) to allow read access on your whole computer. (write access is difficult for multiple reasons, so that's currently missing.) Here's the link to that: https://github.com/zorggn/love-fml
Are PRs welcome?
Yep, i don't make it a secret that i'm human, so i can make mistakes easily!
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.

### Who is online

Users browsing this forum: No registered users and 6 guests