File
| Module | ejs.io |
| Namespace | "ejs.io" |
| Definition | class File |
| Specified | Ejs-11. |
| Inheritance | File Object |
The File class provides a foundation of I/O services to interact with physical files.
Each File object represents a single file, a named path to data stored in non-volatile memory. A File object provides methods for creating, opening, reading, writing and deleting a file, and for accessing and modifying information about the file.
Properties
| Qualifiers | Property | Type | Description |
|---|---|---|---|
| public const | Append | Number | File access mode representing a file opened for append write access. |
| public const | Closed | Number | File access mode representing a Closed file. |
| public const | Create | Number | File access mode where the file will be re-created when opened. |
| public const | Open | Number | File access mode representing an Opened file. |
| public const | Read | Number | File access mode representing an opened file for read access. |
| public const | Truncate | Number | File access mode where the file will be truncated when opened. |
| public const | Write | Number | File access mode representing an opened file for write access. |
File Methods
| Qualifiers | Method |
|---|---|
| public get | absolutePath(): String |
| Return an absolute path name for the file. | |
| public get | basename(): String |
| Get the base name of a file. | |
| public | close(graceful: Boolean): Void |
| Close the input stream and free up all associated resources. | |
| public | copy(toPath: String): Void |
| Copy a file. | |
| public get | created(): Date |
| Get when the file was created. | |
| public static | createTempFile(directory: String): File |
| public get | dirname(): String |
| Get the directory name portion of a file. | |
| public get | exists(): Boolean |
| Test to see if this file exists. | |
| public get | extension(): String |
| Get the file extension portion of the file name. | |
| File(path: String) | |
| Create a new File object and set the file object's path. | |
| public | flush(): Void |
| Flush the stream and the underlying file data. | |
| public | freeSpace(path: String): Number |
| Return the free space in the file system. | |
| iterator override | get(deep: Boolean): Iterator |
| Get an iterator for this file to be used by "for (v in files)". | |
| public static | getBytes(path: String): ByteArray |
| Get the file contents as an array of lines. | |
| public | getFiles(enumDirs: Boolean): Array |
| Get a list of files in a directory. | |
| public static | getLines(path: String, encoding: String): Array |
| Get the file contents as an array of lines. | |
| public static | getString(path: String, encoding: String): String |
| Get the file contents as a string. | |
| iterator override | getValues(deep: Boolean): Iterator |
| Get an iterator for this file to be used by "for each (v in obj)". | |
| public static | getXML(path: String): XML |
| Get the file contents as an XML object. | |
| public get | hasDriveSpec(): Boolean |
| Determine if the file path has a drive spec (C:) in it's name. | |
| public get | isDir(): Boolean |
| Determine if the file name is a directory. | |
| public get | isOpen(): Boolean |
| Determine if the file is currently open for reading or writing. | |
| public get | isRegular(): Boolean |
| Determine if the file name is a regular file. | |
| public get | lastAccess(): Date |
| Get when the file was last accessed. | |
| public get | length(): Number |
| Get the length of the file associated with this File object. | |
| public | makeDir(permissions: Number): Void |
| Make a new directory. | |
| public get | mode(): Number |
| Get the file access mode. | |
| public get | modified(): Date |
| Get when the file was created or last modified. | |
| public get | name(): String |
| Get the name of the file associated with this File object. | |
| public get | newline(): String |
| Return the new line characters. | |
| public set | newline(terminator: String): Void |
| Set the new line characters. | |
| public | open(mode: Number, permissions: Number): Void |
| Open a file using the current file name. | |
| public static | openBinaryStream(filename: String, mode: Number, permissions: Number): BinaryStream |
| Open a file and return a BinaryStream object. | |
| public static | openFileStream(filename: String, mode: Number, permissions: Number): File |
| Open a file and return a Stream object. | |
| public static | openTextStream(filename: String, mode: Number, permissions: Number): TextStream |
| Open a file and return a TextStream object. | |
| public get | parent(): String |
| Get the parent directory of the absolute path of the file. | |
| public get | pathDelimiter(): String |
| Return the path segment delimiter. | |
| public set | pathDelimiter(delim: String): Void |
| Set the path segment delimiter. | |
| public get | permissions(): Number |
| Get the file security permissions. | |
| public set | permissions(mask: Number): Void |
| Set the file security permissions. | |
| public get | position(): Number |
| Get the current I/O position in the file. | |
| public set | position(value: Number): Void |
| Seek to a new location in the file and set the File marker to a new read/write position. | |
| public static | put(path: String, permissions: Number, args: Array): Void |
| Put the file contents. | |
| public | read(buffer: ByteArray, offset: Number, count: Number): Number |
| Read a block of data from a file into a byte array. | |
| public | readBytes(count: Number): ByteArray |
| Read data bytes from a file and return a byte array containing the data. | |
| public get | relativePath() |
| Return a relative path name for the file. | |
| public | remove(): Void |
| Delete the file associated with the File object. | |
| public | removeDir(recursive: Boolean): Void |
| Removes a directory. | |
| public | rename(toFile: String): Void |
| Rename a file. | |
| public | setCallback(callback: Function): Void |
| Put the file stream into async mode and define a completion callback. | |
| public get | unixPath(): String |
| Return an absolute unix style path name for the file. | |
| public | write(items: Array): Number |
| Write data to the file. |
Method Detail
Return an absolute path name for the file.
- Returns
- A string containing an absolute file name relative to the file system's root directory. The file name is canonicalized such that multiple directory separators and ".." segments are removed.
- See Also
- relativePath
Get the base name of a file.
- Description
- Returns the base name portion of a file name. The base name portion is the trailing portion without any directory elements.
- Returns
- A string containing the base name portion of the file name.
Close the input stream and free up all associated resources.
- Parameters
graceful: Boolean if true, then close the file gracefully after writing all pending data. [default: true]
Get when the file was created.
- Returns
- A date object with the date and time or null if the method fails.