Hallo
How can i create a new folder in the internal memory to save my file.
For examble a will save my file in the folder "newfolder" which does not exist and I want it to be created.
When I do, it sends me an error message
Blockquote Error 2103: The file /storage/emulated/0/newfoder/file.txt could not be created
You can take advantage of this error. When this error occurs, use the file save block instead of adding to the file.
In the error event block, put the condition: if error = 2103 then save file - file.txt.
And is this method difficult? Append to file cannot create folders, so you need to create a folder and a file the first time.
Anke
April 24, 2021, 3:16pm
5
kopernikus:
there is no easier way?
For extension, see here .
Note : This won't work after AI2 is targeting API 30 (Android 11), Aug 2021. Then you have to use the ASD.
Thanks you for your help
Patryk_F:
You can take advantage of this error. When this error occurs, use the file save block instead of adding to the file.
In the error event block, put the condition: if error = 2103 then save file - file.txt.
Ηow exactly do i do it? Can you write the Block code? I do not know exactly how to write it. I wrote it below but somewhere I am wrong
Taifun
April 24, 2021, 4:21pm
8
kopernikus:
Ηow exactly do i do it?
use the Screen.ErrorOccurred event to catch the error
Taifun
Trying to push the limits! Snippets , Tutorials and Extensions from Pura Vida Apps by Taifun.
Patryk_F:
I tried it, it does not show me the wrong message now but:
I do not see anywhere the folder "newfolder" and file.txt
Whatever number I put instead of 2103 again does the above.
What Android? Check if it creates a file without a folder: "/file.txt"
I tested it. It turns out that the file component cannot create folders. Use the extension @Anke pointed out.
After creating a folder, you may find that the AppendToFile Block may not create a file in the folder, if so use my method to create the file itself.
Unfortunately, the components aren't very advanced when it comes to file management.
ABG
April 25, 2021, 12:30am
12
Did I miss the memo about \n becoming a legal character in file names?
Anke
April 25, 2021, 12:37pm
13
To create the folder without an extension on all Android versions (in the ASD):
See also here:
How to save a file (text, Canvas: image) read and share it on all Android versions.
[grafik]
Note:
You cannot share a text file from the → Private dir (internal storage):
/data/user/0/<packageName>/files/
@Anke
Really? GetApiLevel1 and GetASD1 do not appear to be native Blocks.
Where do they come from? Something is missing?
Anke
April 25, 2021, 1:07pm
15
I wrote
and this is correct, because this is done by the Canvas
component (and not an ext.). GetASD
only points to the ASD. This is also possible with this:
Here is an easy way to get → App Specific Directory (ASD) & → packageName on all Android Versions without extensions: getASD.aia (8.8 KB)
Get → ASD
[grafik]
Get → packageName
[grafik]
Screenshot <a class="lightbox" href="https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/uploads/default/original/3X/3/f/3f94ecb53dda588c2d1ca6a929ea90a09531cf3b.png" data-download-href="https://community-appinventor-mit-edu.ezproxy.canberra.edu.au/uploads/default/3f94ecb53dda588c2d1ca6a929ea90a09531cf3b" title=&q…
And GetApiLevel
is also possible with this:
You can use this procedure to compare the version numbers even if the number has major, minor, and patch numbers:
[platform greater than or equal to procedure]
For example, it should work correctly if you test against "4.4.2" as a version even though it isn't a mathematical number.
easrng
April 25, 2021, 2:28pm
16
It always has been allowed, the Files app shows it as a space though.