Printing file name from system.DocumentsDirectory

I’m having trouble retrieving a file from system.DocumentsDirectory (only one file in the directory as of now) and storing it as a variable to be displayed on the screen. 

So far I’ve tried various methods with no luck: 

local path = system.pathForFile( “myRecording.mp3”, system.DocumentsDirectory )

    local fhd = io.input( path)

    local pathname = io.read( fhd );

    local filedisplay = string.format( “File:”, path )

   

Anybody got any ideas? 

Thanks

Hi @shawnrm,

So basically, you want to show only the filename part on the screen, like “myRecording.mp3”?

If you already know the file name (because you’re using it for "system.pathForFile()), why not just store that as a variable and use it for both that call and for displaying it on screen?

If that file name may vary, then how about using “string.find()” to trim off just the file name part of the entire path string (“path” in your code) and display that to the screen?

https://docs.coronalabs.com/api/library/string/find.html

Best regards,

Brent

Use this library to discover and print the file names in the documents directory:

https://github.com/GlitchGames/GGFile

This code will print out the file names you want:

local GGFile = require( "GGFile" ) local fileManager = GGFile:new() local files = fileManager:getFilesInDirectory( "", system.DocumentsDirectory ) for i = 1, #files, 1 do print( files[i] ) end

Hi @shawnrm,

So basically, you want to show only the filename part on the screen, like “myRecording.mp3”?

If you already know the file name (because you’re using it for "system.pathForFile()), why not just store that as a variable and use it for both that call and for displaying it on screen?

If that file name may vary, then how about using “string.find()” to trim off just the file name part of the entire path string (“path” in your code) and display that to the screen?

https://docs.coronalabs.com/api/library/string/find.html

Best regards,

Brent

Use this library to discover and print the file names in the documents directory:

https://github.com/GlitchGames/GGFile

This code will print out the file names you want:

local GGFile = require( "GGFile" ) local fileManager = GGFile:new() local files = fileManager:getFilesInDirectory( "", system.DocumentsDirectory ) for i = 1, #files, 1 do print( files[i] ) end