File¶
Non-Visible componentCategory | Requires | Version |
---|---|---|
Storage | API 19, Android 4.4 - 4.4.4 KitKat | 6 |
Overview¶
Non-visible component for storing and retrieving files. Use this component to write or read files on your device. The default behaviour is to write files to the private data directory associated with your App. The Companion is special cased to write files to /sdcard/Kodular/data to facilitate debugging. If the file path starts with a slash (/), then the file is created relative to /sdcard. For example writing a file to /myFile.txt will write the file in /sdcard/myFile.txt.
Events¶
After File Saved¶
Event indicating that the contents of the file have been written.
Params | |
---|---|
file Name | Text |
After Unzip¶
Event indicating that the zip file have been created.
After Zip¶
Event indicating that the zip file have been created.
Directory Created¶
Event indicating that there was a directory created. The return value is 'true' or 'false'.
Params | |
---|---|
is Directory Created | Boolean |
Got Text¶
Event indicating that the contents from the file have been read.
Params | |
---|---|
text | Text |
On Zip Failure¶
Event indicating that there was any failure on zip or unzip a file.
Params | |
---|---|
error Message | Text |
Methods¶
Append To File¶
Appends text to the end of a file storage, creating the file if it does not exist. See the help text under SaveFile for information about where files are written.
Params | |
---|---|
text | Text |
file Name | Text |
Copy¶
Copy a file. If input path started with two // (slashes) then it's a asset file. You can not copy a file into the assets directory.
Params | |
---|---|
input | Text |
output | Text |
Create Directory¶
Create a new directory.
Params | |
---|---|
directory | Text |
Delete¶
Deletes a file from storage. Prefix the filename with / to delete a specific file in the SD card, for instance /myFile.txt. will delete the file /sdcard/myFile.txt. If the file does not begin with a /, then the file located in the programs private storage will be deleted. Starting the file with // is an error because assets files cannot be deleted.
Params | |
---|---|
file Name | Text |
Exists¶
Returns: Boolean
Check whether a file exists. If file path started with two // (slashes) then it means you would check if a asset file exists.
Params | |
---|---|
file | Text |
File Size¶
Returns: Number
Get file size
Params | |
---|---|
file | Text |
Get File Name¶
Returns: Text
Get file name
Params | |
---|---|
file | Text |
Get Free Space¶
Returns: Number
Get Free Space
Params | |
---|---|
path | Text |
Get Total Space¶
Returns: Number
Get total space
Params | |
---|---|
path | Text |
Is Directory¶
Returns: Boolean
Check whether the path is a directory
Params | |
---|---|
path | Text |
Is File¶
Returns: Boolean
Check whether the path is a file
Params | |
---|---|
path | Text |
Move¶
Returns: Boolean
Move a file. You can not move asset files.
Params | |
---|---|
input | Text |
output | Text |
Read From¶
Reads text from a file in storage. Prefix the filename with / to read from a specific file on the SD card. for instance /myFile.txt will read the file /sdcard/myFile.txt. To read assets packaged with an application (also works for the Companion) start the filename with // (two slashes). If a filename does not start with a slash, it will be read from the applications private storage (for packaged apps) and from /sdcard/AppInventor/data for the Companion.
Params | |
---|---|
file Name | Text |
Save File¶
Saves text to a file. If the filename begins with a slash (/) the file is written to the sdcard. For example writing to /myFile.txt will write the file to /sdcard/myFile.txt. If the filename does not start with a slash, it will be written in the programs private data directory where it will not be accessible to other programs on the phone. There is a special exception for the AI Companion where these files are written to /sdcard/AppInventor/data to facilitate debugging. Note that this block will overwrite a file if it already exists If you want to add content to a file use the append block.
Params | |
---|---|
text | Text |
file Name | Text |
Unzip¶
Unzip a file with or without a password. If you dont need a passwort then let it empty.
Params | |
---|---|
target Zip File Path | Text |
destination Folder Path | Text |
password | Text |
Zip¶
Create a zip file with or without a password.
Params | |
---|---|
target Path | Text |
destination File Path | Text |
password | Text |
Properties¶
Legacy Mode¶
Boolean Default: False Read Write - Designer Blocks
Allows app to access files from the root of the external storage directory (legacy mode).