Titanium.Filesystem
> Titanium.Filesystem

The top level filesystem module, used to access files and directories on the device.

For examples of using the Filesystem APIs, refer to the Filesystem Access and Storage guide as well as the other Filesystem submodule API documentation.

Examples

Getting a directory for an application group (iOS)

This example writes a string to a text file in a shared directory

var suiteDir = Ti.Filesystem.directoryForSuite('group.appc.Sharing');
if (!suiteDir) {
    logInApp('Suite Directory not found, check Entitlements.');
    return;
}
var f = Ti.Filesystem.getFile(suiteDir,'emptyfile.txt');
f.write('The file is no longer empty!');
  • 0.8
  • 0.8
  • 0.8
Defined By

Properties

Titanium.Filesystem
IOS_FILE_PROTECTION_COMPLETE : Stringreadonly

Constant used to set protection key to NSFileProtectionComplete in file attributes.

Constant used to set protection key to NSFileProtectionComplete in file attributes.

File is stored in an encrypted format on disk. Cannot be read from or written to while the device is locked or booting.

  • 4.1.0
  • 4.1.0
Titanium.Filesystem
IOS_FILE_PROTECTION_COMPLETE_UNLESS_OPEN : Stringreadonly

Constant used to set protection key to NSFileProtectionCompleteUnlessOpen in file attributes.

Constant used to set protection key to NSFileProtectionCompleteUnlessOpen in file attributes.

File is stored in an encrypted format on disk. Can be created while the device is locked, but once closed, cannot be opened again until the device is unlocked. If the file is opened when unlocked, you may continue to access the file normally, even if the user locks the device.

  • 4.1.0
  • 4.1.0

Constant used to set protection key to NSFileProtectionCompleteUntilFirstUserAuthentication in file attributes.

Constant used to set protection key to NSFileProtectionCompleteUntilFirstUserAuthentication in file attributes.

File is stored in an encrypted format on disk. Cannot be accessed until after the device has booted. After the user unlocks the device for the first time, your app can access the file and continue to access it even if the user subsequently locks the device.

  • 4.1.0
  • 4.1.0
Titanium.Filesystem
IOS_FILE_PROTECTION_NONE : Stringreadonly

Constant used to set protection key to NSFileProtectionNone in file attributes.

Constant used to set protection key to NSFileProtectionNone in file attributes.

File will have no special protection associated with it. Can be read from or written to at any time.

  • 4.1.0
  • 4.1.0
Titanium.Filesystem
MODE_APPEND : Numberreadonly

Constant for append mode for file operations.

Constant for append mode for file operations.

Titanium.Filesystem
MODE_READ : Numberreadonly

Constant for read mode for file operations.

Constant for read mode for file operations.

Titanium.Filesystem
MODE_WRITE : Numberreadonly

Constant for write mode for file operations.

Constant for write mode for file operations.

apiName : Stringreadonly

The name of the API that this proxy corresponds to.

The name of the API that this proxy corresponds to.

The value of this property is the fully qualified name of the API. For example, Button returns Ti.UI.Button.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Titanium.Filesystem
applicationCacheDirectory : Stringreadonly

Path to the application's internal cache directory.

Path to the application's internal cache directory.

Files stored in the cache directory remain after the application is closed but at the discretion of the operating system.

On the Android platform, the cache is limited to 25 MB and the files remain for the lifetime of the application, that is, until the application is uninstalled.

On the iOS platform, the cache does not have a size limit but the data remains until iOS cleans the directory to recover the disk space.

  • 1.8.3
  • 1.8.3
  • 1.8.3
Titanium.Filesystem
applicationDataDirectory : Stringreadonly

Path to the application's data directory.

Path to the application's data directory.

This is a writable directory that can be used to store applications-specific files.

On iOS, this directory is specifically designated for user documents, and a separate directory, applicationSupportDirectory is used for other application data.

On iOS, files in this directory are backed up unless the remoteBackup flag is set to false.

On Android, files in this directory cannot be accessed by other applications, so it should not be used for files that must be used by another application (for example, a video file that will be passed to the system's video player application). These files should be stored in the externalStorageDirectory.

Titanium.Filesystem
applicationDirectory : Stringreadonly

Path to the iOS application directory.

Path to the iOS application directory.

  • 0.8
  • 0.8
Titanium.Filesystem
applicationSupportDirectory : Stringreadonly

Path to the application support directory.

Path to the application support directory.

This is a writable directory used on iOS for application files that are not user documents--including settings files, caches, and so on.

On iOS, files in this directory are backed up unless the remoteBackup flag is set to false.

  • 0.8
  • 0.8
Indicates if the proxy will bubble an event to its parent. ...

Indicates if the proxy will bubble an event to its parent.

Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.

Default: true

  • 3.0.0
  • 3.0.0
  • 3.0.0
Titanium.Filesystem
externalStorageDirectory : Stringreadonly

Path to a directory on removable storage, such as SD card.

Path to a directory on removable storage, such as SD card.

This directory can be used for storing arbitrary data. It is read/write and files in this directory can be passed to other applications, such as video players--which is not possible with the applicationDataDirectory.

This directory may not be subject to as many memory limitations as the applicationDataDirectory, which is stored in the device's internal storage. Note, however, that the user may remove or replace the removable storage device without warning, so the application must be prepared to handle this case gracefully.

The application should check isExternalStoragePresent before accessing this location. The application should also handle any exceptions generated if the storage device is unmounted during use, or if the files stored on external storage are not available.

  • 0.8

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.

If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.

  • 3.6.0
Titanium.Filesystem
lineEnding : Stringreadonly

Platform-specific line ending constant.

Platform-specific line ending constant.

Titanium.Filesystem
resRawDirectory : Stringreadonly

Path to the application's raw resource directory.

Path to the application's raw resource directory.

On Android, the raw resources directory can be used for resources that need to be accessed as individual files, not included in the Android resources bundle. For example, sound files placed in the raw resources directory can be accessed by notifications, which cannot access sound files from the resource directory.

To use raw resources, place files in the platform/android/res/raw folder, where platform is at the top level of the project, not inside the Resources folder. You will need to create the platform folder and subfolders.

This directory is read-only. If you need to modify any files in this directory, they must first be copied to another directory, such as applicationDataDirectory or tempDirectory.

  • 3.0.2
Titanium.Filesystem
resourcesDirectory : Stringreadonly

Path to the application's resource directory.

Path to the application's resource directory.

This directory is read-only. If you need to modify any files in this directory, they must first be copied to another directory, such as applicationDataDirectory or tempDirectory.

On iOS, writable files can also be placed in the applicationSupportDirectory. On Android, writable files can also be placed in the externalStorageDirectory.

Note that when running on the simulator, the resources directory may be writable, but it is not writable on device.

Titanium.Filesystem
separator : Stringreadonly

Platform-specific path separator constant.

Platform-specific path separator constant.

Titanium.Filesystem
tempDirectory : Stringreadonly

Path for the application's temporary directory.

Path for the application's temporary directory.

This directory can be used for storing temporary files. Files in this directory may not persist when the application is shut down and restarted.

Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

Applies the properties to the proxy.

Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Creates a temporary directory and returns a File object representing the new directory. ...

Creates a temporary directory and returns a File object representing the new directory.

Returns

Creates a temporary file and returns a File object representing the new file. ...

Creates a temporary file and returns a File object representing the new file.

Returns

Titanium.Filesystem
( suiteName ) : String
Returns the path to the container directory associated with the specified security application group ID. ...

Returns the path to the container directory associated with the specified security application group ID.

This is a writable directory used on iOS. Groups of sandboxed apps that need to share files and other information can request a container directory as part of their entitlements.

When called with a valid group identifier, this method returns the location of that directory as a string. Returns null if the group identifier is invalid; check the app's entitlements.

  • 4.0.0
  • 4.0.0

Parameters

  • suiteName : String

    The name of the suite.

Returns

  • String
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the applicationCacheDirectory property. ...

Gets the value of the applicationCacheDirectory property.

  • 1.8.3
  • 1.8.3
  • 1.8.3

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the applicationDataDirectory property. ...

Gets the value of the applicationDataDirectory property.

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the applicationDirectory property. ...

Gets the value of the applicationDirectory property.

  • 0.8
  • 0.8

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the applicationSupportDirectory property. ...

Gets the value of the applicationSupportDirectory property.

  • 0.8
  • 0.8

Returns

  • String
Titanium.Filesystem
( path ) : Titanium.Blob
Returns a Blob object representing the asset catalog image identified by the path arguments. ...

Returns a Blob object representing the asset catalog image identified by the path arguments.

Requires: iOS 9.0 and later

This method is only applicable on images in assets catalogs for apps with app-thinning enabled on iOS. Since the bundled image has been reallocated into assets catalog, it is no longer accessible via the original file path. To obtain a Blob object representing this image, use the original file path as the parameter in this method instead of using it in getFile

Similar to getFile, this method takes a variable number of arguments, where each argument is treated as a path component. All of the arguments are joined together using the platform-specific path separator to make the final path.

If a relative path is passed, the full path should be interpreted relative to the current file. For example, if the file Resources/login/login.js contains the following code:

var icon = Titanium.Filesystem.getAsset('icon.png');

The path is interpreted as Resources/login/icon.png.

On iOS, all relative paths are currently interpreted as relative to the Resources directory, not to the current context. This is a known issue that will be addressed in a future release.

  • 5.4.0
  • 5.4.0

Parameters

  • path : String

    One or more path components. Path arguments are joined together using the platform specific path separator to form the full path.

Returns

Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Filesystem
( ) : String
Gets the value of the externalStorageDirectory property. ...

Gets the value of the externalStorageDirectory property.

  • 0.8

Returns

  • String
Titanium.Filesystem
( path ) : Titanium.Filesystem.File
Returns a File object representing the file identified by the path arguments. ...

Returns a File object representing the file identified by the path arguments.

Note that getFile does not create a file if one does not exist at the specified path. It returns a new File object referring to the specified file path. The application can create a file at that path by calling write or create a directory by calling createDirectory on the File object.

This method takes a variable number of arguments, where each argument is treated as a path component. All of the arguments are joined together using the platform-specific path separator to make the final path.

If a relative path is passed, the full path should be interpreted relative to the current file. For example, if the file Resources/login/login.js contains the following code:

var icon = Titanium.Filesystem.getFile('icon.png');

The path is interpreted as Resources/login/icon.png.

On iOS, all relative paths are currently interpreted as relative to the Resources directory, not to the current context. This is a known issue that will be addressed in a future release.

On iOS9, if app thinning is enabled, and the file of interest is an image file that was bundled with the app (not downloaded during runtime), this will not return the image file since it is already allocated inside the assets catalog. Please use getAsset instead for this case.

Parameters

  • path : String

    One or more path components. Path arguments are joined together using the platform specific path separator to form the full path.

Returns

Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Titanium.Filesystem
( ) : String
Gets the value of the lineEnding property. ...

Gets the value of the lineEnding property.

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the resRawDirectory property. ...

Gets the value of the resRawDirectory property.

  • 3.0.2

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the resourcesDirectory property. ...

Gets the value of the resourcesDirectory property.

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the separator property. ...

Gets the value of the separator property.

Returns

  • String
Titanium.Filesystem
( ) : String
Gets the value of the tempDirectory property. ...

Gets the value of the tempDirectory property.

Returns

  • String
Titanium.Filesystem
( ) : Boolean
Returns true if the app has storage permissions. ...

Returns true if the app has storage permissions.

  • 5.4.0

Returns

  • Boolean
Titanium.Filesystem
( ) : Boolean
Returns true if the device supports external storage and the external storage device is mounted. ...

Returns true if the device supports external storage and the external storage device is mounted.

Returns true on Android if an external storage device, such as an SD card, is available for reading and writing.

Returns false on iOS.

Returns

  • Boolean
Titanium.Filesystem
( mode, path ) : Titanium.Filesystem.FileStream
Opens file using the Titanium.IOStream interface. ...

Opens file using the Titanium.IOStream interface.

Parameters

  • mode : Number

    Access mode.

    This API can be assigned the following constants:

  • path : String

    One or more path components. Path arguments are joined together using the platform-specific path separator to form the full path.

Returns

Removes the specified callback as an event listener for the named event. ...

Removes the specified callback as an event listener for the named event.

Multiple listeners can be registered for the same event, so the callback parameter is used to determine which listener to remove.

When adding a listener, you must save a reference to the callback function in order to remove the listener later:

var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);

To remove the listener, pass in a reference to the callback function:

window.removeEventListener('click', listener);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Titanium.Filesystem
( callback )
Requests for storage permissions ...

Requests for storage permissions

On Android, the request view will show if the permission is not accepted by the user, and the user did not check the box "Never ask again" when denying the request. If the user checks the box "Never ask again," the user has to manually enable the permission in device settings.

This method requests Manifest.permission.READ_EXTERNAL_STORAGE. If you require other permissions, you can also use Titanium.Android.requestPermissions.

  • 5.4.0

Parameters

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void