Reading text files from internal project directory

Hello,

I am trying to read the contents of various text files to display the titles of songs in a rhythm game. 

The following code is what i currently have. The output definitely works but the io.open section is not reading the contents. (When test text is substituted it functions perfectly)

The text files are contained in a ‘songs’ folder inside the project folder. I understand that there is a system.DocumentsDirectory folder but I am not sure where it is located for Win32 apps?

for i=1,10 do freemode\_songRect = display.newRect( 303 ,(50\*i), 594, 50 ) freemode\_songRect.strokeWidth = 3 freemode\_songRect:setFillColor( 1,1,1,0 ) freemode\_songRect:setStrokeColor( 1,1,1 ) scrollView:insert(freemode\_songRect) local file, errorString = io.open( "songs/" .. i .. ".txt", "r" ) if not file then -- Error occurred; output the cause print( "File error: " .. errorString ) else -- Read data from file local contents = file:read( "\*a" ) -- Output the file contents freemode\_songRectText = display.newText( contents, 30,(50\*i), "ahgr.ttf", 20 ) freemode\_songRectText.anchorX = 0 freemode\_songRectText.align = "left" scrollView:insert(freemode\_songRectText) -- Close the file handle io.close( file ) end file = nil table.insert(freemode\_songRectList, i) table.insert(freemode\_songRectTextList, i) end

To clarify, your text files are named 1.txt, 2.txt, 3.txt etc correct?

Yep, that is correct.

Your project folder is system.ResourcesDirectory.  The system.DocumentsDirectory is something like C:\Users\yourname\appdata\Roaming\Your Company Name\Application Invasion\Documents 

Your Company Name comes from whatever you fill in for that field on the Build dialog box. 

Rob

To clarify, your text files are named 1.txt, 2.txt, 3.txt etc correct?

Yep, that is correct.

Your project folder is system.ResourcesDirectory.  The system.DocumentsDirectory is something like C:\Users\yourname\appdata\Roaming\Your Company Name\Application Invasion\Documents 

Your Company Name comes from whatever you fill in for that field on the Build dialog box. 

Rob