PhoneGap - File System Actions

Description

Performs actions with the mobile device file system such as creating, reading, deleting file, creating directories, etc.(Only applies to UX components running in a PhoneGap shell.)

Discussion

A collection of actions that make working with files in the mobile device file system easier.

When you choose this action, you can select from the following list of file system actions:

All PhoneGap file system actions are asynchronous. When you define any of these actions you specify a success function that gets called once the PhoneGap action has successfully completed.

 File System Action Properties

  •  Action name

    Specify the File System Action that you want to perform.

    •  Get Directory Contents

      Gets the contents of a directory on a mobile device. Once the directory has been obtained, the onSuccess callback function is called. If an error occurred, the OnFailure callback function is called. The onSuccess callback function is passed an array. The array has an object for each item in the directory. The item object has these properties:

      fullPath
      the full path of the file
      isFile
      true/false - indicates if the entry is a file (true) or a directory (false)
      display
      fullPath followed by either [F] or [D] to indicate if the entry is a file or a directory
    •  Get Directory Contents (Recursive)

      Similar to the 'Get Directory Content' action, but recurses into directories to get the contents of all child directories. Once all of the directories have been read, the onSuccess callback function is called. If there is an error reading any of the directories, the OnFailure callback function is called. This function is passed an array which has an object for each item (file or directory). The item object has these properties:

      fullPath
      the full path of the file
      isFile
      true/false - indicates if the entry is a file (true) or a directory (false)
      display
      fullPath followed by either [F] or [D] to indicate if the entry is a file or a directory
    •  Create Directory

      Creates a directory in the mobile device file system.

    •  Remove Directory

      Deletes a directory from the mobile device file system. For example if you specify 'dir1/dir2' as the name of the directory to remove it will remove 'dir2'.

      See also the Remove Directory Recursive action which removes directories recursively. For example, if you specify 'dir1/dir2' as the name of the directory to remove, it will remove both 'dir1' and 'dir1/dir2'.

    •  Remove Directory (Recursive)

      Removes a directory recursively. For example, if you specify 'dir1/dir2' as the name of the directory to remove, it will remove both 'dir1' and 'dir1/dir2'.

    •  Create File

      Creates a new text file. The filename can include a full path (e.g. dir1/dir2/file.txt). The directory structure for the target file must exists. After the file has been created the onSuccess function is called. If the file was not created, the OnFailure function is called.

    •  Delete File

      Deletes a file. The filename can include a full path (e.g. dir1/dir2/file.txt). After the file has been deleted the onSuccess function is called. If the file was not deleted, the OnFailure function is called.

    •  File Exists

      Checks if a file exists. The filename can include a full path (e.g. dir1/dir2/file.txt). The onSuccess function is called if there were no errors. Your onSuccess function can reference the 'flagExists' variable which will be true (file exists) or false (file does not exist). If there was an error in trying to check the file, the OnFailure function is called.

    •  Read File

      Reads a text file. The filename can include a full path (e.g. dir1/dir2/file.txt). The onSuccess function is called if there were no errors. Your onSuccess function can reference the 'data' variable which will be the file contents. If there was an error in trying to read the file, the OnFailure function is called.

    •  Get File System RUI for Legacy Persistent Storage

      Gets the URI for the legacy persistent file system.

      All of the actions defined in this builder use the Legacy Persistent File Storage location. If you want to use the newer PhoneGap - File System Actions (File URI Based) to work with any files or directories created by the actions exposed in this genie you will need the URI of the legacy file system.

  •  Directory name

    Specify the name of the directory. You can specify a JavaScript function to call that will return the name of the directory by entering:

    Javascript:your_function_name
    Client-side data cache items are stored in a directory called __AADataCache
  • For example:

    Javascript:getDir
  •  File name

    Specify the name of the file. You can specify a JavaScript function to call that will return the name of the file by entering:

    Javascript:your_function_name
  • For example:

    Javascript:getFilename
  •  Text to write to file

    Specify the text to write to the file. You can specify a JavaScript function to call that will return the text by entering:

    Javascript:your_function_name
  • For example:

    Javascript:getTextToWrite
  •  Append to existing file

    If the file already exists should the text be appended to the file? If true, text will appended, If false, existing file will be removed first. You can specify a JavaScript function to return true/false by entering:

    Javascript:your_function_name
  • For example:

    Javascript:getAppendRule
  •  Starting byte location

    (Optional) Specify the byte position (0 based) at which you want to start reading in the file. If you leave this value (or the 'Ending byte location') blank or the entire file will be read. You can specify a JavaScript function to call that will return this value by entering:

    Javascript:your_function_name
  •  Ending byte location

    (Optional) Specify the byte position (0 based) at which you want to end reading in the file. If you leave this value (or the 'Starting byte location') blank or the entire file will be read. You can specify a JavaScript function to call that will return this value by entering:

    Javascript:your_function_name

 Javascript Callback Functions Properties

  •  OnSuccess

    Specify the JavaScript to execute once the action has completed successfully. If the Action name was Read File, your code can reference the 'data' variable which is the contents of the file. If the Action name action was Get File System URI for Legacy Persistent Storage, your code can reference the 'uri' variable which is the URI of the file system.

  •  OnFailure

    Specify the JavaScript to execute if the action fails.

See Also