Skip to content

File

Non-Visible component
Category Requires Version
Storage API 21, Android 5.0 Lollipop 8

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 a public directory for debugging. Use the More information link to read more about how the File component uses paths and scopes to manage access to files.

Events

After File Saved

Event indicating that the contents of the file have been written.

Param Type
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

⚠ Deprecated

Event indicating that there was a directory created. The return value is 'true' or 'false'.

Param Type
is Directory Created Boolean

Got Text

Event indicating that the contents from the file have been read.

Param Type
text Text

On Zip Failure

Event indicating that there was any failure on zip or unzip a file.

Param Type
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.

Param Type
text Text
file Name Text

Copy

⚠ Deprecated

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. Use CopyFile instead.

Param Type
input Text
output Text

Copy File

Returns: Boolean

Copy the contents from the first file to the second file.

Param Type
from Scope Text
FileScope
from File Name Text
to Scope Text
FileScope
to File Name Text
from Scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared
to Scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Create Directory

⚠ Deprecated

Create a new directory. Use MakeDirectory instead.

Param Type
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.

Param Type
file Name Text

Exists

Returns: Boolean

Tests whether the path exists in the given scope.

Param Type
scope Text
FileScope
path Text
scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

File Size

Returns: Number

Get file size

Param Type
file Text

Get File Name

Returns: Text

Get file name

Param Type
file Text

Get Free Space

Returns: Number

Get Free Space

Param Type
path Text

Get Total Space

Returns: Number

Get total space

Param Type
path Text

Is Directory

Returns: Boolean

Tests whether the path named in the given scope is a directory.

Param Type
scope Text
FileScope
path Text
scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Is File

Returns: Boolean

Check whether the path is a file

Param Type
path Text

List Directory

Returns: List

Get a list of files and directories in the given directory.

Param Type
scope Text
FileScope
directory Name Text
scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Make Directory

Returns: Boolean

Create a new directory for storing files. The semantics of this method are such that it willreturn true if the directory exists at its completion. This can mean that the directory alreadyexisted prior to the call.

Param Type
scope Text
FileScope
directory Name Text
scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Make Full Path

Returns: Text

Converts the scope and path into a single string for other components.

Param Type
scope Text
FileScope
path Text
scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Move

⚠ Deprecated

Returns: Boolean

Move a file. You can not move asset files. Use MoveFile instead.

Param Type
input Text
output Text

Move File

Returns: Boolean

Move a file from one location to another.

Param Type
from Scope Text
FileScope
from File Name Text
to Scope Text
FileScope
to File Name Text
from Scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared
to Scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

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.

Param Type
file Name Text

Remove Directory

Returns: Boolean

Remove a directory from the file system. If recursive is true, then everything is removed. Ifrecursive is false, only the directory is removed and only if it is empty.

Param Type
scope Text
FileScope
directory Name Text
recursive Boolean
scope Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

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.

Param Type
text Text
file Name Text

Unzip

Unzip a file with or without a password. If you dont need a passwort then let it empty.

Param Type
target Zip File Path Text
destination Folder Path Text
password Text

Zip

Create a zip file with or without a password.

Param Type
target Path Text
destination File Path Text
password Text

Properties

Default Scope

Text FileScope Default: App ➖ Write - Designer

Specifies the default scope for files accessed using the File component. The App scope shouldwork for most apps. Legacy mode can be used for apps that predate the newer constraints inAndroid on app file access.

Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Read Permission

Boolean Default: False ➖ Write - Designer

A designer-only property that can be used to enable read access to file storage outside of theapp-specific directories.

Scope

Text FileScope Default: App ➖ Read Write - Blocks

Indicates the current scope for operations such as ReadFrom and SaveFile.

Option Value
App App
Asset Asset
Cache Cache
Legacy Legacy
Private Private
Shared Shared

Write Permission

Boolean Default: False ➖ Write - Designer

A designer-only property that can be used to enable write access to file storage outside of theapp-specific directories.