File
QuickLinks
Properties
Property | Type | Access | Description |
---|---|---|---|
absoluteURI | string | readonly | The full path name for the referenced file in URI notation. |
alias | bool | readonly | If true, the object refers to a file system alias or shortcut. |
created | Date | readonly | The creation date of the referenced file, or null if the object does not refer to a file on disk. |
creator | string | readonly | In Mac OS, the file creator as a four-character string. In Windows or UNIX, value is "????". |
displayName | string | readonly | The localized name of the referenced file, without the path specification. |
encoding | string | r/w | Gets or sets the encoding for subsequent read/write operations. One of the encoding constants listed in the JavaScript Tools Guide. If the value is not recognized, uses the system default encoding.A special encoder, BINARY, is used to read binary files. It stores each byte of the file as one Unicode character regardless of any encoding. When writing, the lower byte of each Unicode character is treated as a single byte to write. |
eof | bool | readonly | When true, a read attempt caused the current position to be at the end of the file, or the file is not open. |
error | string | r/w | A string containing a message describing the most recent file system error. Typically set by the file system, but a script can set it. Setting this value clears any error message and resets the error bit for opened files. Contains the empty string if there is no error. |
exists | bool | readonly | If true, this object refers to a file or file-system alias that actually exists in the file system. |
fs | string | readonly | The name of the file system. This is a class property accessed through the File constructor. Valid values are "Windows", "Macintosh", and "Unix". |
fsName | string | readonly | The platform-specific full path name for the referenced file. |
fullName | string | readonly | The full path name for the referenced file in URI notation. |
hidden | bool | r/w | When true, the file is not shown in the platform-specific file browser. If the object references a file-system alias or shortcut, the flag is altered on the alias, not on the original file. |
length | number | r/w | The size of the file in bytes. Can be set only for a file that is not open, in which case it truncates or pads the file with 0-bytes to the new length. |
lineFeed | string | r/w | How line feed characters are written in the file system. One of the values "Windows", "Macintosh", or "Unix". |
modified | Date | readonly | The date of the referenced file's last modification, or null if the object does not refer to a file on the disk. |
name | string | readonly | The file name portion of the absolute URI for the referenced file, without the path specification. |
parent | Folder | readonly | The Folder object for the folder that contains this file. |
path | string | readonly | The path portion of the absolute URI for the referenced file, without the file name. |
readonly | bool | r/w | When true, prevents the file from being altered or deleted. If the referenced file is a file-system alias or shortcut, the flag is altered on the alias, not on the original file. |
relativeURI | string | readonly | The path name for the object in URI notation, relative to the current folder. |
type | string | readonly | The file type as a four-character string. In Mac OS, the Mac OS file type. In Windows, "appl" for .EXE files, "shlb" for .DLL files and "TEXT" for any other file. |
Methods
File File (path:string)
Creates and returns a new File object referring to a given file system location.
Parameter | Type | Description |
---|---|---|
path | string | The full or partial path name of the file, in platform-specific or URI format. |
bool changePath (path:string)
Changes the path specification of the referenced file.
Parameter | Type | Description |
---|---|---|
path | string | A string containing the new path, absolute or relative to the current folder. |
bool close ()
Closes this open file.
bool copy (target:string File)
Copies this object’s referenced file to the specified target location.
Parameter | Type | Description |
---|---|---|
target | string File | A string with the URI path to the target location, or a File object that references the target location. |
void createAlias (path:string)
Makes this file a file-system alias or shortcut to the specified file.
Parameter | Type | Description |
---|---|---|
path | string | A string containing the path of the target file. |
string decode (uri:string)
Decodes a UTF-8 encoded string as required by RFC 2396, and returns the decoded string.
Parameter | Type | Description |
---|---|---|
uri | string | The UTF-8 encoded string to decode. |
string encode (name:string)
Encodes a string as required by RFC 2396, and returns the encoded string.
Parameter | Type | Description |
---|---|---|
name | string | The string to encode. |
bool execute ()
Executes or opens this file using the appropriate application, as if it had been double-clicked in a file browser.
string getRelativeURI (basePath:string)
Retrieves and returns the path for this file, relative to the specified base path, in URI notation.
Parameter | Type | Description |
---|---|---|
basePath | string | A base path in URI notation. |
bool isEncodingAvailable (name:string)
Reports whether a given encoding is available.
Parameter | Type | Description |
---|---|---|
name | string | The encoding name. |
bool open (mode:string, type:string, creator:string)
Opens the referenced file for subsequent read/write operations. The method resolves any aliases to find the file.
Parameter | Type | Description |
---|---|---|
mode | string | The read-write mode, a single-character string. |
type | string | In Mac OS, the type of a newly created file, a 4-character string. Ignored in Windows and UNIX. |
creator | string | In Mac OS, the creator of a newly created file, a 4-character string. Ignored in Windows and UNIX. |
File openDialog (prompt:string [, filter:any=null] [, multiSelect:bool=false])
Opens a dialog so the user can select one or more files to open.
Parameter | Type | Description |
---|---|---|
prompt | string | The prompt text, displayed if the dialog allows a prompt. |
filter | any | A filter that limits the types of files displayed in the dialog. (default: null) |
multiSelect | bool | When true, the user can select multiple files and the return value is an array. (default: false) |
File openDlg (prompt:string [, filter:any=null] [, multiSelect:bool=false])
Opens the built-in platform-specific file-browsing dialog, in which the user can select an existing file or files, and creates new File objects to represent the selected files.
Parameter | Type | Description |
---|---|---|
prompt | string | A string containing the prompt text, if the dialog allows a prompt. |
filter | any | A filter that limits the types of files displayed in the dialog. (default: null) |
multiSelect | bool | When true, the user can select multiple files and the return value is an array. (default: false) |
string read (chars:number)
Reads the contents of the file, starting at the current position.
Parameter | Type | Description |
---|---|---|
chars | number | An integer specifying the number of characters to read. |
string readch ()
Reads a single text character from the file at the current position.
string readln ()
Reads a single line of text from the file at the current position.
bool remove ()
Deletes the file associated with this object from disk immediately, without moving it to the system trash.
bool rename (newName:string)
Renames the associated file.
Parameter | Type | Description |
---|---|---|
newName | string | The new file name, with no path information. |
File resolve ()
Attempts to resolve the file-system alias or shortcut that this object refers to.
File saveDialog (prompt:string [, filter:any=null])
Opens a dialog so the user can select a file name to save to.
Parameter | Type | Description |
---|---|---|
prompt | string | The prompt text, displayed if the dialog allows a prompt. |
filter | any | A filter that limits the types of files displayed in the dialog. (default: null) |
File saveDlg (prompt:string [, filter:any=null])
Opens the built-in platform-specific file-browsing dialog, in which the user can select an existing file location to which to save information, and creates a new File object to represent the selected file.
Parameter | Type | Description |
---|---|---|
prompt | string | A string containing the prompt text, if the dialog allows a prompt. |
filter | any | A filter that limits the types of files displayed in the dialog. (default: null) |
bool seek (pos:number [, mode:number=0])
Seeks to a given position in the file.
Parameter | Type | Description |
---|---|---|
pos | number | The new current position in the file as an offset in bytes from the start, current position, or end, depending on the mode. |
mode | number | The seek mode. (default: 0) |
number tell ()
Retrieves the current position as a byte offset from the start of the file.
string toSource ()
Creates and returns a serialized string representation of this object.
string toString ()
Converts this object to a string.
bool write (text:string)
Writes the specified text to the file at the current position.
Parameter | Type | Description |
---|---|---|
text | string | A text string to be written. |
bool writeln (text:string)
Writes a string to the file at the current position and appends a line-feed sequence.
Parameter | Type | Description |
---|---|---|
text | string | A text string to be written. |
Element of
Reflection.sampleFile
ReflectionInfo.sampleFile
Used in
$.evalFile (file:File [, timeout:number=10000])
File.copy (target:string File)
Return
File File.File (path:string)
File File.openDialog (prompt:string [, filter:any=null] [, multiSelect:bool=false])
File File.openDlg (prompt:string [, filter:any=null] [, multiSelect:bool=false])
File File.resolve ()
File File.saveDialog (prompt:string [, filter:any=null])
File File.saveDlg (prompt:string [, filter:any=null])