Full path of a file

my question is where i put my file in first that i can read it but i don't know where and i can't find it.
If i know the response, i can put my new file in the same place.

grafik

1 Like

I don't understand.
There is no command in app inventor to know the full path of a file that it read ?

Your path for the assets to read a text file is correct:
//myFile.csv

  • starting with // or use
  • FileScope = Asset and myFile.csv

The File component does not use an absolute or full path at all.
With FileScope Legacy or Shared a relative path is used / required.

i do this:

image

with this:
image

and my file is here :
emulated/0/Download/StatesAbbreviation.csv

then i have Error 2101 : The file //StatesAbreviation.csv could not be found

If your file is stored in the external storage:
/storage/emulated/0/Download/StatesAbbreviation.csv
and this file is not created by your app you won't be able to read it with the File component on Android 11+. You must use SAF in this case.

If the file is created by your app, you can read it with the File component using a realtive path and FileScope = Legacy or Shared (as I already said):
/Download/StatesAbbreviation.csv

See also here:

1 Like

Then the file is not created by my app and as i said at the first, i'm on Android 9.
So ,what's your proposal ?

And thanks for your help.

Then do what I suggested and request READ_EXTERNAL_STORAGE permission (not sure if it is still requested automatically since the nb193 release).

This is all you need on Android < 11.

Will that file change or do you want to read it only once? In the last case you could upload it as asset in the media section of the desiger and use the blocks you previously posted

Taifun

See Capital State Country Puzzler - Google Docs

I made some tests to find a solution but i have no success.

I finaly understood why my app read the file at the begining. It's because i load it in the app.

It's the code i used:

and the result :

So, i tried without this load . Then nothing is good.

or that:

The file “TextFile.txt” is placed in :

  • Storage/emulated/0/DCIM
  • Storage/emulated/0/Download
  • Storage/emulated/0/Music

And storage/4160-203F, my SD card.

And I never see what it contains.

I tried with DefaultScope = "ASSET" ou "Shared" and it's the same errors without a slash or with one or two slashes.

Somebody as an app which is ok with the same Android version that i can test ?
Or tell me what is wrong at home ?

Thank's at all.

Post your aia. The problem can be easily solved.

To be clear: you want to copy the text file from Assets to /Download and read it from there?

Try this (test.txt & test2.txt are in the assets):

My aia is posted earlier when i said : "It's the code i used"

And no, i don't want to copy the file, i just want ro read it from /download for exemple.
For me, but perhaps i mistake, "asset" = file created by the app.

The answer already hs been provided here

Unfortunately you did not follow that advice

Taifun

I tried this,

and it works fine :star_struck: And i can also write on my file.
But i was mistaked by this:
https://ai2.appinventor.mit.edu/reference/components/storage.html#File:

  • Legacy: Files will be read from and written to the file system using the App Inventor rules prior to release nb187. That is, file names starting with a single / will be read from and written to the root of the external storage directory, e.g., /sdcard/. Legacy functionality will not work on Android 11 or later.

And so i tried with my sdcard named /4160-203F/. But i think it's mine only and not the others. If i write /4160-203F/TextFile.txt perhaps it go on my phone but what about the others ?

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.