CS3 JS: File

CS3 JavaScript

File

 Represents a file in the local file system in a platform-independent manner.

QuickLinks

File, changePath, close, copy, createAlias, decode, encode, execute, getRelativeURI, isEncodingAvailable, open, openDialog, openDlg, read, readch, readln, remove, rename, resolve, saveDialog, saveDlg, seek, tell, toSource, toString, write, writeln

Properties

PropertyTypeAccessDescription
absoluteURIstringreadonlyThe full path name for the referenced file in URI notation.
aliasboolreadonlyIf true, the object refers to a file system alias or shortcut.
createdDatereadonlyThe creation date of the referenced file, or null if the object does not refer to a file on disk.
creatorstringreadonlyIn Mac OS, the file creator as a four-character string. In Windows or UNIX, value is "????".
displayNamestringreadonlyThe localized name of the referenced file, without the path specification.
encodingstringr/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.

eofboolreadonlyWhen true, a read attempt caused the current position to be at the end of the file, or the file is not open.
errorstringr/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.

existsboolreadonlyIf true, this object refers to a file or file-system alias that actually exists in the file system.
fsstringreadonly

The name of the file system.

This is a class property accessed through the File constructor. Valid values are "Windows", "Macintosh", and "Unix".

fsNamestringreadonlyThe platform-specific full path name for the referenced file.
fullNamestringreadonlyThe full path name for the referenced file in URI notation.
hiddenboolr/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.

lengthnumberr/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.

lineFeedstringr/w

How line feed characters are written in the file system.

One of the values "Windows", "Macintosh", or "Unix".

modifiedDatereadonlyThe date of the referenced file's last modification, or null if the object does not refer to a file on the disk.
namestringreadonlyThe file name portion of the absolute URI for the referenced file, without the path specification.
parentFolderreadonlyThe Folder object for the folder that contains this file.
pathstringreadonlyThe path portion of the absolute URI for the referenced file, without the file name.
readonlyboolr/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.

relativeURIstringreadonlyThe path name for the object in URI notation, relative to the current folder.
typestringreadonly

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.

ParameterTypeDescription
pathstringThe 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.

ParameterTypeDescription
pathstringA 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.

ParameterTypeDescription
targetstring FileA 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.

ParameterTypeDescription
pathstringA 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.

ParameterTypeDescription
uristringThe UTF-8 encoded string to decode.

string encode (name:string)
Encodes a string as required by RFC 2396, and returns the encoded string.

ParameterTypeDescription
namestringThe 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.

ParameterTypeDescription
basePathstringA base path in URI notation.

bool isEncodingAvailable (name:string)
Reports whether a given encoding is available.

ParameterTypeDescription
namestringThe 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.

ParameterTypeDescription
modestringThe read-write mode, a single-character string.
typestringIn Mac OS, the type of a newly created file, a 4-character string. Ignored in Windows and UNIX.
creatorstringIn 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.

ParameterTypeDescription
promptstringThe 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)
multiSelectboolWhen 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.

ParameterTypeDescription
promptstringA 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)
multiSelectboolWhen 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.

ParameterTypeDescription
charsnumberAn 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.

ParameterTypeDescription
newNamestringThe 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.

ParameterTypeDescription
promptstringThe 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.

ParameterTypeDescription
promptstringA 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.

ParameterTypeDescription
posnumber The new current position in the file as an offset in bytes from the start, current position, or end, depending on the mode.
modenumberThe 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.

ParameterTypeDescription
textstringA 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.

ParameterTypeDescription
textstringA 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])

Contents :: Index