See the App Inventor Extensions document about how to use an App Inventor Extension.
For questions about this extension or bug reports please start a new thread in the
App Inventor community. Thank you.
For feature requests please contact me by email.
To be a sponsor of a new method already is possible starting from only 10 USD! With your contribution you will help the complete App Inventor community. Thank you.
Sept 6th, 2015: Fixed the delete button to delete the extension and added a help text for the extension.
Sept 7th, 2015: Added the version number (version 1 as of 2015-09-07) in the help text of the extension.
Oct 12th, 2015: Rebuilt the extension for App Inventor version ai2extensions4 and Companion version 233.cdk2.
Nov 16th, 2015: Copy and Delete blocks added, built for App Inventor version ai2extensions6 and Companion version 235.cdk2.
Mar 11th, 2016: FileList: includeSubdirectories option added, FileListAsync method added.
Mar 25th, 2016: Version 3a: better error message will be provided for Copy block, see also here
Mar 30th, 2016: Version 3b: bug fix for Exists method, see also here
May 5th, 2016: Version 4: GetFileName from media content uri method added
May 8th, 2016: Version 5: DirectoryList method added
Aug 11th, 2016: Version 5b: avoid DX execution failed error: build each extension separately
Dec 19th, 2016: Version 6+7: GetUri, AvailableStorageDirectories, AvailableSize methods added
Dec 30th, 2016: Version 7a: AvailableSize method now works for API Level 9 and above
Jan 16th, 2017: Version 8: new methods Move, CopyAsync and MoveAysnc, new events Copied and Moved added
Sep 10th, 2017: Version 9: new method FileListFromAssets added
March 21th, 2019: Version 10: new methods ApplicationSpecificDirectory and CreateApplicationSpecificDirectory added
July 21th, 2019: Version 11: underlying library for AvailableStrorageDirectories method updated
March 31th, 2020: Version 12: underlying library (latest version as of 23. Oct 2019) for AvailableStrorageDirectories method updated
Oct 23th, 2020: Version 13: Android 11 bugfix (null array) for DirectoryList and FileList: /Android/data and /Android/obb not accessible anymore, FileListFromAssets now also works in Kodular in the companion app and for devices >= API 29
Feb 13th, 2021: Version 13a: bugfix copy from assets concerning check if file exists, path to assets for Kodular companion app still does not use ASD for devices >= API29
Oct 28h, 2021: Version 14: asset path for companion app adjusted according to this post by Anke.
Dec 17h, 2021: Version 14a: Kodular fix... assets directory adjusted for companion app and devices < Android 10, see also this post by Anke.
This extension is related to the file component.
Required permissions: android.permission.READ_EXTERNAL_STORAGE, android.permission.WRITE_EXTERNAL_STORAGE
Note: I decided to not add the SDK 26 functionality into this extension to be more flexible, see especially the new methods in version 10. In case you need it to ask for permissions,
please use the permission blocks from the Screen drawer manually.
Note: Starting with the SDK30 release most of the methods and events of this extension will still work,
except copying files to the external storage (outside the ASD or one of the Shared folders) on devices with Android >= 11,
because WRITE permission does no longer exist on Android 11+ (with targetSdk = 30).
Generally in a perfect App Inventor world my suggestion would be to use the corresponding methods from the file component now. See also the design document
here.
However as the file component still does have some permission issues, you might prefer to continue using the file extension...
Returns whether Warnings should be suppressed
Specifies whether Warnings should be suppressed
Copy file.
Use this method to copy small files, for large files use the CopyAsync method instead.
Prefix the filename with / (i.e. relative path) to copy a file on the SD card.
For instance /myFile.txt will copy the file /mnt/sdcard/myFile.txt. To copy
assets packaged with an application (also works for the Companion) start
the fromFilename with // (two slashes). However you can't copy
files to the assets. If a fileName starts with file:///
you can specify a complete path to the file.
Copy file (asynchronously).
Use this method to copy large files. The copy process is finished after the Copied event fires.
Prefix the filename with / (i.e. relative path) to copy a file on the SD card.
For instance /myFile.txt will copy the file /mnt/sdcard/myFile.txt. To copy
assets packaged with an application (also works for the Companion) start
the fromFilename with // (two slashes). However you can't copy
files to the assets. If a fileName starts with file:/// you can specify a complete path to the file.
Thank you Haider for being the sponsor of this method!
Move file.
Use this method to move small files, for large files use the MoveAsync method instead.
Prefix the filename with / (i.e. relative path) to move a file on the SD card.
For instance /myFile.txt will move the file /mnt/sdcard/myFile.txt. You can't move files from or to the assets.
If a fileName starts with file:/// you can specify a complete path to the file.
Thank you Haider for being the sponsor of this method!
Move file (asynchronously).
Use this method to move large files. The move process is finished after the Moved event fires.
Prefix the filename with / (i.e. relative path) to move a file on the SD card.
For instance /myFile.txt will move the file /mnt/sdcard/myFile.txt. You can't move files from or to the assets
If a fileName starts with file:/// you can specify a complete path to the file.
Thank you Haider for being the sponsor of this method!
Delete file.
Prefix the filename with / (i.e. relative path) to delete a file on the SD card.
For instance /myFile.txt will delete the file /mnt/sdcard/myFile.txt. You can't delete
files stored in the assets! If a fileName starts with file:/// you can specify a complete path to the file.
Note: To delete a file from an external sdcard is currently an experimental feature,
see also this thread.
Return a list of subdirectories of a given directory.
The complete path to these subdirectories is provided.
If a directory starts with file:/// you can specify a complete path to the directory.
The result list does NOT include subdirectories of subdirectories.
Checks whether a file or directory exists.
Prefix the filename with / (i.e. relative path) to look for the file on the SD card.
For instance /myFile.txt will look for the file /mnt/sdcard/myFile.txt. To read
assets packaged with an application (also works for the Companion) start
the filename with // (two slashes). If a fileOrDirectoryName starts with file:///
you can specify a complete path to the file of directory."
Return a list of filenames of a given directory.
Use this method for specific directories to get back a result immediately.
To get a list for a complete device or sdcard, which may take a few seconds, use the FileListAsync method instead.
The complete path to these files is provided. You can filter by extension. To get a list of all files, use * as extension.
If a directory starts with file:/// you can specify a complete path to the directory.
To include files of all subdirectories, set includeSubdirectories to true, else to false.
Thank you Shorty for being the sponsor of the includeSubdirectories option.
Create a list of filenames of a given directory.
The result will be provided in the AfterFileListAsync event.
The complete path to these files is provided. You can filter by extension. To get a list of all files, use * as extension.
If a directory starts with file:/// you can specify a complete path to the directory.
To include files of all subdirectories, set includeSubdirectories to true, else to false.
Thank you Shorty for being the sponsor of the includeSubdirectories option.
Return a list of filenames from the assets (also works for the Companion).
Note: during development, you will get all files stored in directory /AppInventor/assets. You might want to delete this directory before starting the companion app...
Thank you Paolo for being the sponsor of this method.
Checks whether it is a file or directory.
Prefix the filename with / (i.e. relative path) to look for the file on the SD card.
For instance /myFile.txt will look for the file /mnt/sdcard/myFile.txt.
If fileOrDirectoryName starts with file:/// you can specify a complete path to the file or directory.
Return file length of a file.
Prefix the filename with / (i.e. relative path) to look for the file on the SD card.
For instance /myFile.txt will look for the file /mnt/sdcard/myFile.txt. To read
assets packaged with an application (also works for the Companion) start
the filename with // (two slashes). If a fileName starts with file:///
you can specify a complete path to the file.
Get path and filename from media content uri
Thank you Matthew for being the sponsor of this block.
Get content uri from filename
Return a list of available storage directories.
The method uses this snippet.
Thank you HendraWD and Dmitriy
Thank you Hussein for being the sponsor of this method!
Return available size of given storage directory in Bytes.
To get the value in KB, divide by 1024. To get the value in MB, divide by another 1024.
To get the value in GB, divide by another 1024.
Minimum API Level for this method is API Level 9 (Android 2.3)
Thank you Hussein for being the sponsor of this method and thank you SteveJG for your additional tests!
Creates the application specific directory /storage/emulated/0/Android/data/<packageName>/files in case it does not exist.
Returns the application specific directory /storage/emulated/0/Android/data/<packageName>/files you can use to read or write files
without READ_ or WRITE_EXTERNAL_STORAGE permission.
Event indicating that creating a list of files of a given directory has finished.
Event indicating that copying a file has finished, which was started using the CopyAsync method.
In case everything went fine, parameter successful is true.
In case an error occurred, parameter successful is false and parameter response will provide an error message.
Thank you Haider for being the sponsor of this event!
Event indicating that moving a file has finished, which was started using the MoveAsync method.
In case everything went fine, parameter successful is true.
In case an error occurred, parameter successful is false and parameter response will provide an error message.
Thank you Haider for being the sponsor of this event!
Get a list of all music files of the Music directory of your device and play your music in random order.
Jukebox image by Pixabay. Thank you!
Q1: Very helpful component! How to get a file list on External SDCard? I can do only on phone memory?
A: use the full path to the directory, example: file:///storage/extSdCard/myDirectory or file:///storage/sdcard1/myDirectory
or file:///storage/ext_sd/myDirectory.
The full path to the external sdcard is device dependent and might be different for your device...
Q2: Please advise me how to delete a file location that retrieve from ActivityStarter.ResultUri.
For ex. the result is content://media/external/image/media/7004 How can we know the real file path?
A: This is a "content uri". Thank you Matthew for being the sponsor of the GetFileName method.
Q3: Concerning the FileList method: Is there a way to exclude sub directories? I would like to target JUST the root.
A: This is currently not possible, the FileList method returns a list of filenames of a given directory including all subdirectories.
However I could add that as option after having received a donation of 10 USD. Thank you Shorty for being the sponsor of that option.
Q4: Is there a way to delete a folder? Do you plan to implement this in your File Extension component, perhaps with a sponsorship?
A: I did not implement this to prevent people deleting a complete sdcard unintentionally.
See this thread how to delete a folder.
Developing and maintaining snippets, tutorials and extensions for App Inventor takes a lot of time.
I hope it saved some of your time. If yes, then you might consider to donate a small amount!
or donate some mBTC to Address:
1Jd8kXLHu2Vkuhi15TWHiQm4uE9AGPYxi8
Thank you! Taifun
Download TaifunFile extension (aix file)
Download Test Copy and Delete (aia file)
Download Test FileList (aia file)
Download FileListFromAssets Test (aia file)
Download Available Storage Size Test (aia file)
Download Jukebox V2 (aia file)
Note: the Jukebox Example V2 also provides blocks to ask for now necessary permissions.
Thank you Anke!
Back to top of page ...
This work by Pura Vida Apps
is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
with attribution (name=Pura Vida Apps and link to the source site) required.