save/load files on the device

Good night guys ! So I’m working on a project and I got to the final part of it, but, I need to save a file on my own cell phone instead of saving it to the system.DoccumentDirectory folder, for example, saving it to the “downloads” folder … I am using SSK for generate the file … The part of the code that makes me generate the file is this:

name = nameUser .. numberUser .. os.date("%Y%m%d") for j = 1, #c1 do local out = "Movemment: " .. nameUser out = out .. "," .. c1[j] out = out .. ";" out = out .. "\n" io.appendFile( out, name..".csv" ) print("saved") end

Could someone please help me to make the file be saved in a folder accessible by the user’s cell phone ??

I am very desperate looking for this because my application delivery timeout is for tomorrow

@everyone ,

The part of the above code that is SSK, is this function: io.appendFile()

This is an io.* extension added by SSK that lets you append content to an existing file (or create it if the file does not exist yet) in any of the standard system.* directories, excluding system.ResourceDirectory which is generally not writable.

This extension is not intended for the user @pabloapdz is using it for.  However it will likely still work.

I think the real question ‘@pabloapdz’ is asking here is, “What is a path, in Android, that is universally the same, and can be accessed both from an app and from a PC when plugged into the phone with a USB cable?”

I don’t think there is a universal answer to this question, but if anyone has it, please share.

@pabloapdz,

You and I have an ongoing discussion about this here:  https://forums.coronalabs.com/topic/70139-csv-file-with-corona/

I’m cool continuing this discussion here, but generally it is frowned upon to start a new thread if one is on-going.

Having said that, your other thread started about another topic and veered into this one so, again I’m OK continuing here.

So, continuing and re-iterating what I said in the other thread: 

To have ANY hope of this working, you need to   Identify and create a string containing the complete path you want to write to.

You can use SSK files.* to help with this, but you don’t need to.

The key functions that might help are:

  • ssk.files.util.repairPath( _ path _ ) -  Where ‘_ path _’ is the full path and filename you want to write to.  This function ensures it meets the slash-standard for the OS you are on.  So, it is optional.
  • ssk.files.util.writeFile( _ content , _ path _ ) - Where ’ content ’ is a string,number or previously read content and ’ path _’ is the full path and filename you want to write to.
    • This is not that special, but it does ensure you’re using ‘wb’ attribute when writing.

@pabloapdz,

I know you’re ESL and using a translator so let me be clear and concise:

You need to figure out the full path to a place that can be accessed from you PC over usb.

Once you have this, you should be able to write to it from the app too, but that is not guaranteed.

This is NOT a normal thing, or at least not many people here do this.

PS - You said you were in a big hurry.  Can you tell me why?  Is this for a class?  

Anyways, I hope you figure this out soon. :slight_smile:

First, I would like to thank you again for the help on the other topic hahaha <3 Yes, I created this separate topic because I believe the other was no longer the main subject, then I will put there “doubts solved” because thanks to you, the The reason I opened that topic was completely solved! :slight_smile:

And good, I already gave a read in this link that you passed me, but I did not understand very well how to use it … My doubt I think it comes down to: As I will put a way to save the file, being that in the code: io.appendFile (out, name … “.csv”)
there’s no command for me to change the path … I can not see anywhere in it, something that’s saying, “Hey, it’s for you to save exactly in system.DocummentsDirectory” And this is fucking with my head because any solution I find I can not “fit” into the code … For example, where would I place these link codes that you passed me?

Well, I’m desperate to finish (I think that’s why I can not learn anything else) because I get paid to solve these issues, and my boss gave me the deadline until September 9 at 1:00 PM Or either I’m done or I’m fired :slight_smile:

Let me see if I can clarify something for you.
 
The ‘path’ in ssk.files.util.writeFile( _ content path  _)  is  the complete path and filename.
 
So, let’s pretend you want to make a text file called ‘bob.txt’ containing the phrase “Corona Rocks!”.
 
Let’s also pretend  the folder you want to write to is ’ /mnt/sdcard/ext_sd/’
 
You would simply do this:
 

ssk.files.util.writeFile( "Corona Rocks!", "/mnt/sdcard/ext\_sd/bob.txt" )

That is all there is to it.

The big problem you are facing and the one I cannot help you with is:  “What is the path to use that will make the file visible in the way you want it?”

Again, I don’t honestly think there is one consistent path that can be used on all Android mobile devices running all Android versions.

The deadline you’re under seems pretty unreasonable.  I’m sorry to hear that is the case.

This part : “Again, I don’t honestly think there is one consistent path that can be used on all Android mobile devices running all Android versions.” 

It really did give me an immense joy to read. Because ? 

Because I simply need to develop for a device that will always be the same brand and always the same model. So in case, I could get the directory of this device and write it there, right?

Probably.  That is the best I can do.  

Why is it so critical that this CSV file be accessible via USB?  Why not just email it as an attachment?  You can do that too.

Or… are you planning on modifying it from the computer and later re-loading it in your app?

Can you email it easily? My fear is that this solution is very complex … There really is no problem with this, the whole problem is to get it out of the device, I was even thinking about sending through messenger and etc but I thought it would be something more complex … How would it work for me to send it as an attachment?

(No, I would not need to have the file again, after it is removed from the device the file that will stay there turns trash to me)

It was just a suggestion.  The problem is I don’t have a good grasp of your situation and constraints.

I’m calling it a night.  I hope you get this worked out.

Well, I really have a lot to thank you, thanks to you I solved my big problem (: In the near future, I come back here to tell you what was the final solution, about how I managed to find some “universal way” Words are not enough for how much you helped me! Now I’m going to sleep I’m going to get up early tomorrow Good night and all the best for you :slight_smile:

@everyone ,

The part of the above code that is SSK, is this function: io.appendFile()

This is an io.* extension added by SSK that lets you append content to an existing file (or create it if the file does not exist yet) in any of the standard system.* directories, excluding system.ResourceDirectory which is generally not writable.

This extension is not intended for the user @pabloapdz is using it for.  However it will likely still work.

I think the real question ‘@pabloapdz’ is asking here is, “What is a path, in Android, that is universally the same, and can be accessed both from an app and from a PC when plugged into the phone with a USB cable?”

I don’t think there is a universal answer to this question, but if anyone has it, please share.

@pabloapdz,

You and I have an ongoing discussion about this here:  https://forums.coronalabs.com/topic/70139-csv-file-with-corona/

I’m cool continuing this discussion here, but generally it is frowned upon to start a new thread if one is on-going.

Having said that, your other thread started about another topic and veered into this one so, again I’m OK continuing here.

So, continuing and re-iterating what I said in the other thread: 

To have ANY hope of this working, you need to   Identify and create a string containing the complete path you want to write to.

You can use SSK files.* to help with this, but you don’t need to.

The key functions that might help are:

  • ssk.files.util.repairPath( _ path _ ) -  Where ‘_ path _’ is the full path and filename you want to write to.  This function ensures it meets the slash-standard for the OS you are on.  So, it is optional.
  • ssk.files.util.writeFile( _ content , _ path _ ) - Where ’ content ’ is a string,number or previously read content and ’ path _’ is the full path and filename you want to write to.
    • This is not that special, but it does ensure you’re using ‘wb’ attribute when writing.

@pabloapdz,

I know you’re ESL and using a translator so let me be clear and concise:

You need to figure out the full path to a place that can be accessed from you PC over usb.

Once you have this, you should be able to write to it from the app too, but that is not guaranteed.

This is NOT a normal thing, or at least not many people here do this.

PS - You said you were in a big hurry.  Can you tell me why?  Is this for a class?  

Anyways, I hope you figure this out soon. :slight_smile:

First, I would like to thank you again for the help on the other topic hahaha <3 Yes, I created this separate topic because I believe the other was no longer the main subject, then I will put there “doubts solved” because thanks to you, the The reason I opened that topic was completely solved! :slight_smile:

And good, I already gave a read in this link that you passed me, but I did not understand very well how to use it … My doubt I think it comes down to: As I will put a way to save the file, being that in the code: io.appendFile (out, name … “.csv”)
there’s no command for me to change the path … I can not see anywhere in it, something that’s saying, “Hey, it’s for you to save exactly in system.DocummentsDirectory” And this is fucking with my head because any solution I find I can not “fit” into the code … For example, where would I place these link codes that you passed me?

Well, I’m desperate to finish (I think that’s why I can not learn anything else) because I get paid to solve these issues, and my boss gave me the deadline until September 9 at 1:00 PM Or either I’m done or I’m fired :slight_smile:

Let me see if I can clarify something for you.
 
The ‘path’ in ssk.files.util.writeFile( _ content path  _)  is  the complete path and filename.
 
So, let’s pretend you want to make a text file called ‘bob.txt’ containing the phrase “Corona Rocks!”.
 
Let’s also pretend  the folder you want to write to is ’ /mnt/sdcard/ext_sd/’
 
You would simply do this:
 

ssk.files.util.writeFile( "Corona Rocks!", "/mnt/sdcard/ext\_sd/bob.txt" )

That is all there is to it.

The big problem you are facing and the one I cannot help you with is:  “What is the path to use that will make the file visible in the way you want it?”

Again, I don’t honestly think there is one consistent path that can be used on all Android mobile devices running all Android versions.

The deadline you’re under seems pretty unreasonable.  I’m sorry to hear that is the case.

This part : “Again, I don’t honestly think there is one consistent path that can be used on all Android mobile devices running all Android versions.” 

It really did give me an immense joy to read. Because ? 

Because I simply need to develop for a device that will always be the same brand and always the same model. So in case, I could get the directory of this device and write it there, right?

Probably.  That is the best I can do.  

Why is it so critical that this CSV file be accessible via USB?  Why not just email it as an attachment?  You can do that too.

Or… are you planning on modifying it from the computer and later re-loading it in your app?

Can you email it easily? My fear is that this solution is very complex … There really is no problem with this, the whole problem is to get it out of the device, I was even thinking about sending through messenger and etc but I thought it would be something more complex … How would it work for me to send it as an attachment?

(No, I would not need to have the file again, after it is removed from the device the file that will stay there turns trash to me)

It was just a suggestion.  The problem is I don’t have a good grasp of your situation and constraints.

I’m calling it a night.  I hope you get this worked out.