Page 1 of 1

[SOLVED] getDirectoryItems() and getInfo()

Posted: Sun May 12, 2019 2:27 pm
by trabitboy
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

Re: getDirectoryItems() and getInfo()

Posted: Sun May 12, 2019 5:14 pm
by zorg
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)

Re: getDirectoryItems() and getInfo()

Posted: Mon May 13, 2019 7:40 pm
by trabitboy
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

Re: getDirectoryItems() and getInfo()

Posted: Tue May 14, 2019 4:26 pm
by pgimeno
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.

similar issue with getDirectoryItems() and getInfo()

Posted: Sun Jun 02, 2019 8:59 am
by mxmlnbndsmnn
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?

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

Posted: Sun Jun 02, 2019 9:13 am
by grump
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.

similar issue with getDirectoryItems() and getInfo()

Posted: Sun Jun 02, 2019 1:24 pm
by mxmlnbndsmnn
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?

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

Posted: Sun Jun 02, 2019 2:41 pm
by zorg
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

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

Posted: Sun Jun 02, 2019 2:58 pm
by grump
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?

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

Posted: Sun Jun 02, 2019 6:25 pm
by zorg
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! :3