Module: ko/file

Facilitates common file actions. It works slightly differently than the mozilla io/file module which likes to throw exceptions when a simple return false is more desirable (eg. calling basename on a path that doesn't exist)

Methods


require("ko/file").basename(path)

Returns the last component of the given path. For example, basename("/foo/bar/baz") returns "baz". If the path has no components, the empty string is returned.

Parameters:
Name Type Description
path String

The file path

Returns:
Type
String

require("ko/file").copy(path, toDirname)

Copy the given file to the given directory

Parameters:
Name Type Description
path String

The file path

toDirname String

The target file path


require("ko/file").create(path, name)

Create a file at the given location (like touch)

Parameters:
Name Type Description
path String

The path

name String

The file name


require("ko/file").createTemp(name)

Create a temporary file, this file is not automatically deleted by Komodo ie. the deleting is handled by the OS/platform

Parameters:
Name Type Description
name String
Returns:

path to temp file

Type
String

require("ko/file").dirname(path)

Returns the path of the directory containing the given file. If the file is at the top of the volume, the empty string is returned.

Parameters:
Name Type Description
path String

The folder path

Returns:
Type
String

require("ko/file").exists(path)

Returns true if a file exists at the given path and false otherwise.

Parameters:
Name Type Description
path String

The file path

Returns:
Type
Boolean

require("ko/file").isDir(path)

Returns true only if this path specifies a directory.

Parameters:
Name Type Description
path String

The directory path


require("ko/file").isFile(path)

Returns true only if this path specifies a file.

Parameters:
Name Type Description
path String

The file path


require("ko/file").join()

Takes a variable number of strings, joins them on the file system's path separator, and returns the result.

Parameters:
Name Type Description
... Strings

A variable number of strings to join. The first string must be an absolute path. eg. join("foo","bar","baz") // foo\bar\baz

Returns:

A single string formed by joining the strings on the file system's path separator.

Type
String

require("ko/file").list(path)

Returns an array of file names in the given directory.

Parameters:
Name Type Description
path String

The file path

Returns:
Type
Array

require("ko/file").mkpath(path)

Makes a new directory named by the given path. Any subdirectories that do not exist are also created. mkpath can be called multiple times on the same path.

Parameters:
Name Type Description
path String

The file path


require("ko/file").move(path, toDirname)

Move (cut/paste) the given file to the given directory

Parameters:
Name Type Description
path String

The file path

toDirname String

The target file path


require("ko/file").open(path [, mode])

Returns a stream providing access to the contents of a file.

For more details see https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/io_file#open.

Parameters:
Name Type Argument Default Description
path String

The file path

mode String <optional>
r

The file mode, r|w|b

Returns:
Type
Stream

require("ko/file").openTemp(name [, mode])

Open a temporary file with the given name as a seed, the file is removed when the stream is closed

Parameters:
Name Type Argument Default Description
name String

The file path

mode String <optional>
r

The file mode, r|w|b

Returns:
Type
Stream

require("ko/file").read(path, mode)

Opens a file and returns a string containing its entire contents.

Parameters:
Name Type Description
path String

The file path

mode String

Can be "b" to read in binary mode

Returns:
Type
String

require("ko/file").remove(path)

Removes a file from the file system. To remove directories, use rmdir.

Parameters:
Name Type Description
path String

The file path


require("ko/file").rename(path, newName)

Rename the given file

Parameters:
Name Type Description
path String

The file path

newName String

The new file name


require("ko/file").rmdir(path)

Removes a directory from the file system. If the directory is not empty, an exception is thrown.

Parameters:
Name Type Description
path String

The file path