RhoFile

Enterprise Browser 3.3

Overview

This API provides several methods for access to files and folders found on the device's local file system.

Enabling the API

There are two methods of enabling the RhoFile API:

  • Include all ebapi modules
  • Include only the required API modules

For either of these methods, you'll need to include files from the /Enterprise Browser/JavaScript Files/Enterprise Browser directory on the computer that you installed the Enterprise Browser.

Include all JS API modules

To include all JS APIs, copy the ebapi-modules.js file to a location accessible by the app's files and include a reference to the JavaScript file in the app's HTML. For instance, to include the modules file in the app's index.html, copy the file to the same directory as that index.html and add the following line to the HTML's HEAD section:


<script type="text/javascript" charset="utf-8" src="ebapi-modules.js"></script>

Note: that the pathing for this file is relative to the current page.

This will define the EB class within the page. Any page you need to use the modules will need to have the .js file included in this fashion.

Include only the required modules

To include single APIs, you must first include the ebapi.js in your HTML as well as the API file you want to use. For instance, to use the RhoFile API, I would add the following code to my HTML file(s), assuming the API files have been copied to the same directory as the HTML.


<script type="text/javascript" charset="utf-8" src="ebapi.js"></script>
<script type="text/javascript" charset="utf-8" src="eb.file.js"></script>

The ebapi.js file is necessary for all single API inclusions.

Methods

basename(STRING path)

Return basename part for the specified path. Will remove any prefix up to the last path separator ('/' or '\' depending on platform). Example: for path '/full/path/to/file.ext' basename will return 'file.ext'.

Parameters

  • path : STRING

    Absolute path for which basename is given.

  • callback : CallBackHandler

Callback

Async Callback Returning Parameters: STRING

    Returns

    Synchronous Return:

    • STRING : Basename part for the given path.

    Platforms

    • Android
    • Windows Mobile
    • Windows CE

    Method Access:

    • Class Method: This method can only be accessed via the API class object.
      • EB.RhoFile.basename(STRING path)

    Destructor close()

    Closes file. Once Close method is invoked, no file object will be alive.

    Parameters

    • callback : CallBackHandler

    Returns

    Synchronous Return:

    • Void

    Platforms

    • Android
    • Windows Mobile
    • Windows CE

    Method Access:

    • Class Method: This method is a destructor and can only be accessed via the object that was created by the new constructor.
      • myObj.close()

    copy(STRING from, STRING to)

    Copies file from "from" (source) to "to" (destination).

    Parameters

    • from : STRING

      File name to be copied.

    • to : STRING

      Destination path.

    • callback : CallBackHandler

    Callback

    Async Callback Returning Parameters: INTEGER

      Returns

      Synchronous Return:

      • INTEGER : Error code raised during copy operation. 0 if no error.

      Platforms

      • Android
      • Windows Mobile
      • Windows CE

      Method Access:

      • Class Method: This method can only be accessed via the API class object.
        • EB.RhoFile.copy(STRING from, STRING to)

      deleteDir(STRING path)

      Deletes specified directory. The specified directory must be empty to be deleted.

      Parameters

      • path : STRING

        Absolute path to the directory to be deleted.

      • callback : CallBackHandler

      Callback

      Async Callback Returning Parameters: INTEGER

        Returns

        Synchronous Return:

        • INTEGER : Error code raised on directory deletion. 0 on success, -1 otherwise.

        Platforms

        • Android
        • Windows Mobile
        • Windows CE

        Method Access:

        • Class Method: This method can only be accessed via the API class object.
          • EB.RhoFile.deleteDir(STRING path)

        deleteFile(STRING path)

        Deletes file.

        Parameters

        • path : STRING

          Absolute path to the file to be deleted.

        • callback : CallBackHandler

        Callback

        Async Callback Returning Parameters: INTEGER

          Returns

          Synchronous Return:

          • INTEGER : Error code raised on file deletion. 0 on success, -1 otherwise.

          Platforms

          • Android
          • Windows Mobile
          • Windows CE

          Method Access:

          • Class Method: This method can only be accessed via the API class object.
            • EB.RhoFile.deleteFile(STRING path)

          deleteRecursive(STRING path, BOOLEAN leaveRoot)

          Deletes all directory contents.

          Parameters

          • path : STRING

            Absolute path to the directory.

          • leaveRoot : BOOLEAN Optional Default: false

            Set to true if you only want to delete directory contents, but no the directory itself.

          • callback : CallBackHandler

          Returns

          Synchronous Return:

          • Void

          Platforms

          • Android
          • Windows Mobile
          • Windows CE

          Method Access:

          • Class Method: This method can only be accessed via the API class object.
            • EB.RhoFile.deleteRecursive(STRING path, BOOLEAN leaveRoot)

          dirname(STRING path)

          Returns directory name part of the specified path.

          Parameters

          • path : STRING

            Absolute path to directory.

          • callback : CallBackHandler

          Callback

          Async Callback Returning Parameters: STRING

            Returns

            Synchronous Return:

            • STRING : Directory name.

            Platforms

            • Android
            • Windows Mobile
            • Windows CE

            Method Access:

            • Class Method: This method can only be accessed via the API class object.
              • EB.RhoFile.dirname(STRING path)

            exists(STRING path)

            Checks if specified path exists.

            Parameters

            • path : STRING

              Absolute path to file or directory.

            • callback : CallBackHandler

            Callback

            Async Callback Returning Parameters: BOOLEAN

              Returns

              Synchronous Return:

              • BOOLEAN : True if path exists, otherwise false.

              Platforms

              • Android
              • Windows Mobile
              • Windows CE

              Method Access:

              • Class Method: This method can only be accessed via the API class object.
                • EB.RhoFile.exists(STRING path)

              flush()

              Flushes all buffered data to the storage media.

              Parameters

              • callback : CallBackHandler

              Returns

              Synchronous Return:

              • Void

              Platforms

              • Android
              • Windows Mobile
              • Windows CE

              Method Access:

              • Instance Method: This method can be accessed via an instance object of this class:
                • myObject.flush()

              getFileSize(STRING path)

              Returns size of the file.

              Parameters

              • path : STRING

                Absolute path to the file.

              • callback : CallBackHandler

              Callback

              Async Callback Returning Parameters: INTEGER

                Returns

                Synchronous Return:

                • INTEGER : File size in bytes.

                Platforms

                • Android
                • Windows Mobile
                • Windows CE

                Method Access:

                • Class Method: This method can only be accessed via the API class object.
                  • EB.RhoFile.getFileSize(STRING path)

                isDir(STRING path)

                Checks if specified path is a directory.

                Parameters

                • path : STRING

                  Absolute path of the directory.

                • callback : CallBackHandler

                Callback

                Async Callback Returning Parameters: BOOLEAN

                  Returns

                  Synchronous Return:

                  • BOOLEAN : True if path is a directory. False otherwise.

                  Platforms

                  • Android
                  • Windows Mobile
                  • Windows CE

                  Method Access:

                  • Class Method: This method can only be accessed via the API class object.
                    • EB.RhoFile.isDir(STRING path)

                  isFile(STRING path)

                  Checks if specified path is a file.

                  Parameters

                  • path : STRING

                    Absolute path of the file.

                  • callback : CallBackHandler

                  Callback

                  Async Callback Returning Parameters: BOOLEAN

                    Returns

                    Synchronous Return:

                    • BOOLEAN : True if path is a file, false otherwise.

                    Platforms

                    • Android
                    • Windows Mobile
                    • Windows CE

                    Method Access:

                    • Class Method: This method can only be accessed via the API class object.
                      • EB.RhoFile.isFile(STRING path)

                    isOpened()

                    Checks if file is opened.

                    Parameters

                    • callback : CallBackHandler

                    Callback

                    Async Callback Returning Parameters: BOOLEAN

                      Returns

                      Synchronous Return:

                      • BOOLEAN : True if file is opened, false otherwise.

                      Platforms

                      • Android
                      • Windows Mobile
                      • Windows CE

                      Method Access:

                      • Instance Method: This method can be accessed via an instance object of this class:
                        • myObject.isOpened()

                      join(STRING p1, STRING p2)

                      Joins two parts of the path considering all necessary path delimiters. I.e.: join('/path/to','file') will return '/path/to/file'

                      Parameters

                      • p1 : STRING

                        First part of the path.

                      • p2 : STRING

                        Second part of the path.

                      • callback : CallBackHandler

                      Callback

                      Async Callback Returning Parameters: STRING

                        Returns

                        Synchronous Return:

                        • STRING : Joined path.

                        Platforms

                        • Android
                        • Windows Mobile
                        • Windows CE

                        Method Access:

                        • Class Method: This method can only be accessed via the API class object.
                          • EB.RhoFile.join(STRING p1, STRING p2)

                        listDir(STRING path)

                        Lists all entries of specified directory.

                        Parameters

                        • path : STRING

                          Absolute path to directory.

                        • callback : CallBackHandler

                        Callback

                        Async Callback Returning Parameters: ARRAY

                          Returns

                          Synchronous Return:

                          • ARRAY : Array of directory entry names. If directory is empty array of size 0 will be returned.

                          Platforms

                          • Android
                          • Windows Mobile
                          • Windows CE

                          Method Access:

                          • Class Method: This method can only be accessed via the API class object.
                            • EB.RhoFile.listDir(STRING path)

                          makeDir(STRING path)

                          Creates directory with the provided path. If all top-level nodes of the path doesn't exists, directory will not be created.

                          Parameters

                          • path : STRING

                            Path to the new directory.

                          • callback : CallBackHandler

                          Callback

                          Async Callback Returning Parameters: INTEGER

                            Returns

                            Synchronous Return:

                            • INTEGER : Error code raised on directory creation. 0 on success, -1 otherwise.

                            Platforms

                            • Android
                            • Windows Mobile
                            • Windows CE

                            Method Access:

                            • Class Method: This method can only be accessed via the API class object.
                              • EB.RhoFile.makeDir(STRING path)

                            makeDirs(STRING path)

                            Creates directory and all top-level directories if necessary. Subsequent isDir call is necessary to check if path was successfully created.

                            Parameters

                            • path : STRING

                              Absolute path to the directory to be created.

                            • callback : CallBackHandler

                            Returns

                            Synchronous Return:

                            • Void

                            Platforms

                            • Android
                            • Windows Mobile
                            • Windows CE

                            Method Access:

                            • Class Method: This method can only be accessed via the API class object.
                              • EB.RhoFile.makeDirs(STRING path)

                            Constructor new EB.RhoFile(STRING path, INTEGER mode)

                            Opens file in a mode specified by the "mode" parameter.

                            Parameters

                            • path : STRING

                              Absolute path to the file.

                            • mode : INTEGER

                              Mode in which to open the file.

                              Possible Values :

                              Constant: EB.RhoFile.OPEN_FOR_APPEND
                              String:1
                              Open file for output at the end of a file. The file is created if it does not exist.
                              Constant: EB.RhoFile.OPEN_FOR_READ
                              String:2
                              Open file for read-only operations. The file must exist.
                              Constant: EB.RhoFile.OPEN_FOR_WRITE
                              String:3
                              Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.
                              Constant: EB.RhoFile.OPEN_FOR_READ_WRITE
                              String:4
                              Open a file for update (both for read and write). The file must exist.
                            • callback : CallBackHandler

                            Returns

                            Synchronous Return:

                            • Void

                            Platforms

                            • Android
                            • Windows Mobile
                            • Windows CE

                            Method Access:

                            • Class Method: This method is a constructor and can only be accessed via the new construct.
                              • var myObj = new EB.RhoFile(STRING path, INTEGER mode)

                            read(STRING path)

                            Reads specified file to a string object.

                            Parameters

                            • path : STRING

                              Absolute path to file.

                            • callback : CallBackHandler

                            Callback

                            Async Callback Returning Parameters: STRING

                              Returns

                              Synchronous Return:

                              • STRING : File contents.

                              Platforms

                              • Android
                              • Windows Mobile
                              • Windows CE

                              Method Access:

                              • Class Method: This method can only be accessed via the API class object.
                                • EB.RhoFile.read(STRING path)

                              read(INTEGER size)

                              Reads specified number of characters from current position of the file.

                              Parameters

                              • size : INTEGER

                                Number of characters to be read.

                              • callback : CallBackHandler

                              Callback

                              Async Callback Returning Parameters: STRING

                                Returns

                                Synchronous Return:

                                • STRING : String from current position of file containing specified number of characters.

                                Platforms

                                • Android
                                • Windows Mobile
                                • Windows CE

                                Method Access:

                                • Instance Method: This method can be accessed via an instance object of this class:
                                  • myObject.read(INTEGER size)

                                readAll()

                                Reads all file contents to the string object.

                                Parameters

                                • callback : CallBackHandler

                                Callback

                                Async Callback Returning Parameters: STRING

                                  Returns

                                  Synchronous Return:

                                  • STRING : Contents of the file.

                                  Platforms

                                  • Android
                                  • Windows Mobile
                                  • Windows CE

                                  Method Access:

                                  • Instance Method: This method can be accessed via an instance object of this class:
                                    • myObject.readAll()

                                  rename(STRING from, STRING to)

                                  Renames / moves file.

                                  Parameters

                                  • from : STRING

                                    Original path / name.

                                  • to : STRING

                                    New path / name.

                                  • callback : CallBackHandler

                                  Callback

                                  Async Callback Returning Parameters: INTEGER

                                    Returns

                                    Synchronous Return:

                                    • INTEGER : Error code raised on move / rename. 0 on success, -1 otherwise.

                                    Platforms

                                    • Android
                                    • Windows Mobile
                                    • Windows CE

                                    Method Access:

                                    • Class Method: This method can only be accessed via the API class object.
                                      • EB.RhoFile.rename(STRING from, STRING to)

                                    seek(INTEGER pos)

                                    Sets file position to specified value from the beginning of the file.

                                    Parameters

                                    • pos : INTEGER

                                      Position within the file.

                                    • callback : CallBackHandler

                                    Returns

                                    Synchronous Return:

                                    • Void

                                    Platforms

                                    • Android
                                    • Windows Mobile
                                    • Windows CE

                                    Method Access:

                                    • Instance Method: This method can be accessed via an instance object of this class:
                                      • myObject.seek(INTEGER pos)

                                    size()

                                    Returns file size.

                                    Parameters

                                    • callback : CallBackHandler

                                    Callback

                                    Async Callback Returning Parameters: INTEGER

                                      Returns

                                      Synchronous Return:

                                      • INTEGER : File size in bytes.

                                      Platforms

                                      • Android
                                      • Windows Mobile
                                      • Windows CE

                                      Method Access:

                                      • Instance Method: This method can be accessed via an instance object of this class:
                                        • myObject.size()

                                      write(STRING val)

                                      Writes the provided string at current position in the file.

                                      Parameters

                                      • val : STRING

                                        String to be written to the file.

                                      • callback : CallBackHandler

                                      Callback

                                      Async Callback Returning Parameters: INTEGER

                                        Returns

                                        Synchronous Return:

                                        • INTEGER : Number of bytes written.

                                        Platforms

                                        • Android
                                        • Windows Mobile
                                        • Windows CE

                                        Method Access:

                                        • Instance Method: This method can be accessed via an instance object of this class:
                                          • myObject.write(STRING val)

                                        Remarks

                                        SD Card Access

                                        SD Card access is disabled on devices running Android 11 (and later). Learn more.

                                        Any references to device path must be directed to:

                                        • /enterprise/device/enterprisebrowser or
                                        • /Android/data/com.zebra.mdna.enterprisebrowser/

                                        Examples

                                        Create and Read the file using File API

                                        This example demonstrate how to create and read the file using File API.

                                        
                                        //Set the file path
                                        var path = EB.RhoFile.join(EB.Application.userFolder, "testFile.txt");
                                        
                                        //Create the file
                                        function createFile()
                                        {
                                            if (EB.RhoFile.exists(path))
                                            {
                                                EB.RhoFile.deleteFile(path);
                                            }
                                            var fWrite = new EB.RhoFile(path,EB.RhoFile.OPEN_FOR_READ_WRITE);
                                            fWrite.write("This is Enterprise Browser File API.");
                                            fWrite.close();
                                        }
                                        
                                        //Read the file
                                        function readFile()
                                        {
                                           var fOpen = new EB.RhoFile(path,EB.RhoFile.OPEN_FOR_READ);
                                           var data = fOpen.readAll();
                                           document.getElementById("myText").innerHTML = data;
                                           fOpen.close();
                                        }