File I/O
Use this API to access local files for reading and writing. Only string data can be read and written with this API. Please note that binary files are not supported. Strings filled with \0 will be truncated to the last non \0 character.
This API is part of the coreapi
extension that is included automatically.
extensions: ["coreapi"]
Be sure to review the JavaScript API Usage guide for important information about using this API in JavaScript
Be sure to review the Ruby API Usage guide for important information about using this API in Ruby
Return basename part for the specified path. Will remove any prefix up to the last path separator (‘/’ or ‘\’ depending on platform). Exampe: for path ‘/full/path/to/file.ext’ basename will return ‘file.ext’.
Parameters
Full pathname for which basename is given.
Synchronous Return:
Method Access:
Rho.RhoFile.basename(STRING path)
Rho::RhoFile.basename(STRING path)
Closes file.
Synchronous Return:
Method Access:
myObj.close()
@myObj.close()
Copies file to specified destination.
Parameters
File name to be copied.
Destination path.
Synchronous Return:
Method Access:
Rho.RhoFile.copy(STRING from, STRING to)
Rho::RhoFile.copy(STRING from, STRING to)
Deletes directory. Non-empty directory will not be deleted.
Parameters
Full path to the directory to be deleted.
Synchronous Return:
Method Access:
Rho.RhoFile.deleteDir(STRING path)
Rho::RhoFile.deleteDir(STRING path)
Deletes file.
Parameters
Full path to the file to be deleted.
Synchronous Return:
Method Access:
Rho.RhoFile.deleteFile(STRING path)
Rho::RhoFile.deleteFile(STRING path)
Deletes all directory contents.
Parameters
Path to the directory.
Set to true if you only want to delete directory contents, but no the directory itself.
Synchronous Return:
Method Access:
Rho.RhoFile.deleteRecursive(STRING path, BOOLEAN leaveRoot)
Rho::RhoFile.deleteRecursive(STRING path, BOOLEAN leaveRoot)
Returns directory name part of the specified path.
Parameters
Path.
Synchronous Return:
Method Access:
Rho.RhoFile.dirname(STRING path)
Rho::RhoFile.dirname(STRING path)
Checks if specified path exists.
Parameters
Full pathname of file or directory.
Synchronous Return:
Method Access:
Rho.RhoFile.exists(STRING path)
Rho::RhoFile.exists(STRING path)
Flushes all buffered data to the storage media.
Synchronous Return:
Method Access:
myObject.flush()
Returns size of the file.
Parameters
Path to the file.
Synchronous Return:
Method Access:
Rho.RhoFile.getFileSize(STRING path)
Rho::RhoFile.getFileSize(STRING path)
Checks if specified path is a directory.
Parameters
Full pathname of the directory.
Synchronous Return:
Method Access:
Rho.RhoFile.isDir(STRING path)
Rho::RhoFile.isDir(STRING path)
Checks if specified path is a file.
Parameters
Full pathname of the file.
Synchronous Return:
Method Access:
Rho.RhoFile.isFile(STRING path)
Rho::RhoFile.isFile(STRING path)
Checks if file is opened.
Synchronous Return:
Method Access:
myObject.isOpened()
Joins two parts of the path concidering all necessary path delimiters. I.e.: join(‘/path/to’,‘file’) will return ‘/path/to/file’
Parameters
First part of the path.
Second part of the path.
Synchronous Return:
Method Access:
Rho.RhoFile.join(STRING p1, STRING p2)
Rho::RhoFile.join(STRING p1, STRING p2)
Lists all entries of specified directory.
Parameters
Directory path.
Synchronous Return:
Method Access:
Rho.RhoFile.listDir(STRING path)
Rho::RhoFile.listDir(STRING path)
Creates directory. If all top-level nodes of the path doesn’t exists, directory will not be created.
Parameters
Path to the new directory.
Synchronous Return:
Method Access:
Rho.RhoFile.makeDir(STRING path)
Rho::RhoFile.makeDir(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 to the directory to be created.
Synchronous Return:
Method Access:
Rho.RhoFile.makeDirs(STRING path)
Rho::RhoFile.makeDirs(STRING path)
Opens file in specified mode.
Parameters
Path to file.
File open mode.
Possible Values :
Synchronous Return:
Method Access:
var myObj = new Rho.RhoFile(STRING path, INTEGER mode)
@myObj = Rho::RhoFile.new(STRING path, INTEGER mode)
Reads specified file to a string object.
Parameters
Path to file.
Synchronous Return:
Method Access:
Rho.RhoFile.read(STRING path)
Rho::RhoFile.read(STRING path)
Reads specified number of symbols from current position of the file.
Parameters
Number of symbols to be read.
Synchronous Return:
Method Access:
myObject.read(INTEGER size)
Reads all file contents to the string object.
Synchronous Return:
Method Access:
myObject.readAll()
Renames/moves file.
Parameters
Original path.
New path.
Synchronous Return:
Method Access:
Rho.RhoFile.rename(STRING from, STRING to)
Rho::RhoFile.rename(STRING from, STRING to)
Sets file position to specified value from the beginning of the file.
Parameters
File position.
Synchronous Return:
Method Access:
myObject.seek(INTEGER pos)
Returns file size.
Synchronous Return:
Method Access:
myObject.size()
Writes passed string at current position.
Parameters
String to be written.
Synchronous Return:
Method Access:
myObject.write(STRING val)
var folders = []; var files = []; var root_path = "/arbitrary/path" var entries = Rho.File.listDir(root_path); for (var i = 0; i < entries.length; i++) { var entry = entries[i]; if ((entry != ".") && (entry != "..")) { (Rho.RhoFile.isDir(Rho.RhoFile.join(root_path, entry)) ? folders : files).push(entry); } }
folders = [] files = [] root_path = "/arbitrary/path" entries = Rho::File.listDir(root_path) entries.each do |entry| unless (entry == "." || entry == "..") (Rho::File.isDir(Rho::File.join(root_path,entry)) ? folders : files) << entry end end