Problems with lfs

I have a problem with lfs (lua file system).

I’m trying to display all files that reside in DocumentsDirectory in a tableView. But the for-loop doesn’t produce any output, although I have files in there (for example, settings.json) (the tableView functions are commented, as they are not problematic).

I’m using build 2076 and Win8.

Code which I use is the following:

    local doc_path = system.pathForFile( “”, system.DocumentsDirectory )
    print (doc_path)
    --tableView:insertRow(options)
    for ifile in require(“lfs”).dir(doc_path) do
        print ("Found file " … ifile)
        --options.id = ifile
        --tableView:insertRow(options)
    end

Thanks in advance for any tips :slight_smile:

Is there any reason why you are not requiring the lfs module at the top of your app instead of trying to require it in for loop?

I took your code, cleaned out the commented out lines:

  local doc\_path = system.pathForFile( "", system.DocumentsDirectory )     print (doc\_path)     for ifile in require("lfs").dir(doc\_path) do         print ("Found file " .. ifile)     end

Ran it, and got this in my log:

2014-01-05 11:54:18.602 Corona Simulator[954:507] Found file .
2014-01-05 11:54:18.602 Corona Simulator[954:507] Found file …
2014-01-05 11:54:18.603 Corona Simulator[954:507] Found file dattalives.db
2014-01-05 11:54:18.603 Corona Simulator[954:507] Found file test.db

And those are the files in that folder, so the code works.  Now I’m on a Mac with the latest daily build, but there have not been any LFS changes in a long time.  The only variable here is Windows 8 and I have no way to check it.  I would try moving your main.lua to a temporary file and create a new main.lua with just that code in it and run it and see what prints in your log file.  Then you can use Corona’s File->Show Project Sandbox and open that folder and make sure the files are there that you expect.

Rob

Rob,

Thank you for your quick answer.

As a matter of fact, I am requiring the “lfs” at the top of the module (I’m using this in one of my scenes), I wrote it like that for the sakes of MWE.

I took your code and placed it at the beginning of my main.lua (though preserved all other code, but I think this should not cause a problem), and the only think it outputs is the print statement with doc_path:

C:\Users\Pjanc\AppData\Roaming\Corona Labs\Corona Simulator\Sandbox\current_development-3B1437598088D2A68C1F4C0ACB78E6D5\Documents\

which is exactly the Documents directory I access using the Project Sandbox shortcut.
 

I hope this information can prove to be useful.

Pjanc

I also tried following your suggestion, having only those 5 lines of code as main.lua.

The output is similar, only the doc_path gets printed.

In the Documents directory, accessed through Project Sandbox, there are a lot of files (.csv, .txt and .json - in case that causes troubles).

Looking forward to the solution of this problem :slight_smile:

I’m going to suggest you file a bug report.  You can use the code I gave you for the sample project.  Since I don’t have Windows 8 I can’t duplicate your environment.  You will get an email with the acknowledgement of the bug report.  Please post the bug ID back here when you are done.

The link is at the very top right of the page by the “Forums” link.

Rob

I’ve filed a bug with number 29423.

Rob, thank you for your help!

Pjanc

Rob

a little input concerning this bug.

I recently changed my user folder name so that it doesn’t include the wildchar “š”, as it is a special one in our language and my name. Now everything works just fine.

Cheers,

Pjanc

Good to know.

Thanks

Rob

Is there any reason why you are not requiring the lfs module at the top of your app instead of trying to require it in for loop?

I took your code, cleaned out the commented out lines:

  local doc\_path = system.pathForFile( "", system.DocumentsDirectory )     print (doc\_path)     for ifile in require("lfs").dir(doc\_path) do         print ("Found file " .. ifile)     end

Ran it, and got this in my log:

2014-01-05 11:54:18.602 Corona Simulator[954:507] Found file .
2014-01-05 11:54:18.602 Corona Simulator[954:507] Found file …
2014-01-05 11:54:18.603 Corona Simulator[954:507] Found file dattalives.db
2014-01-05 11:54:18.603 Corona Simulator[954:507] Found file test.db

And those are the files in that folder, so the code works.  Now I’m on a Mac with the latest daily build, but there have not been any LFS changes in a long time.  The only variable here is Windows 8 and I have no way to check it.  I would try moving your main.lua to a temporary file and create a new main.lua with just that code in it and run it and see what prints in your log file.  Then you can use Corona’s File->Show Project Sandbox and open that folder and make sure the files are there that you expect.

Rob

Rob,

Thank you for your quick answer.

As a matter of fact, I am requiring the “lfs” at the top of the module (I’m using this in one of my scenes), I wrote it like that for the sakes of MWE.

I took your code and placed it at the beginning of my main.lua (though preserved all other code, but I think this should not cause a problem), and the only think it outputs is the print statement with doc_path:

C:\Users\Pjanc\AppData\Roaming\Corona Labs\Corona Simulator\Sandbox\current_development-3B1437598088D2A68C1F4C0ACB78E6D5\Documents\

which is exactly the Documents directory I access using the Project Sandbox shortcut.
 

I hope this information can prove to be useful.

Pjanc

I also tried following your suggestion, having only those 5 lines of code as main.lua.

The output is similar, only the doc_path gets printed.

In the Documents directory, accessed through Project Sandbox, there are a lot of files (.csv, .txt and .json - in case that causes troubles).

Looking forward to the solution of this problem :slight_smile:

I’m going to suggest you file a bug report.  You can use the code I gave you for the sample project.  Since I don’t have Windows 8 I can’t duplicate your environment.  You will get an email with the acknowledgement of the bug report.  Please post the bug ID back here when you are done.

The link is at the very top right of the page by the “Forums” link.

Rob

I’ve filed a bug with number 29423.

Rob, thank you for your help!

Pjanc

Rob

a little input concerning this bug.

I recently changed my user folder name so that it doesn’t include the wildchar “š”, as it is a special one in our language and my name. Now everything works just fine.

Cheers,

Pjanc

Good to know.

Thanks

Rob