Hello,
Is there some possibility of creating subdirectory in Documents Directory?
[lua]local filePath = system.pathForFile( “test/data.txt”, system.DocumentsDirectory )
51
52 – io.open opens a file at filePath. returns nil if no file found
53 local file = io.open( filePath, “r” )
54 if file then
55 – read all contents of file into a string
56 local contents = file:read( “*a” )
57
58 print( "Contents of " … filePath )
59 print( contents )
60
61 io.close( file )
62
63 local t = display.newText( “Finished reading contents of\n” … filePath, 50, 50, nil, 12 );
64 t:setTextColor( 255, 255, 136, 255 );
65 else
66 print( “Creating file…” )
67
68 – create file b/c it doesn’t exist yet
69 file = io.open( filePath, “w” )
70 file:write( “Feed me data!\n” )
71 local numbers = {1,2,3,4,5,6,7,8,9}
72 file:write( numbers[1], numbers[2], numbers[3], “\n” )
73 for _,v in ipairs( numbers ) do
74 file:write( v, " " )
75 end
76 file:write( “\nNo more data\n” )
77 io.close( file )
78
79 local t = display.newText( “Created file at\n” … filePath, 50, 50, nil, 12 );
80 t:setTextColor( 255, 255, 136, 255 );
81
82 – This removes the file just created
83 – os.remove( filePath )
84 end[/lua]
I tried this but program crashes.
How can I create directories. Is this possible at all?
thx
Sumeragi [import]uid: 6869 topic_id: 1538 reply_id: 301538[/import]