File
QuickLinks
Hierarchy
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. |
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. |
Class
Property | Type | Access | Description |
---|---|---|---|
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". |
Methods
Constructor
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. The value stored in the object is the absolute path. The file that the path refers to does not need to exist.If the path refers to an existing folder: • The File function returns a Folder object instead of a File object. • The new operator returns a File object for a nonexisting file with the same name. (Optional) |
Example | new File(path) |
Class
string decode (uri:
string)
Decodes a UTF-8 encoded string as required by RFC 2396, and returns the decoded string.
See also String.decodeURI().
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.
All special characters are encoded in UTF-8 and stored as escaped characters starting with the percent sign followed by two hexadecimal digits. For example, the string "my file" is encoded as "my%20file".
Special characters are those with a numeric value greater than 127, except the following: / - _ . ! ~ * ' ( )
See also encodeURI().
Parameter | Type | Description |
---|---|---|
name | string | The string to encode. |
bool isEncodingAvailable (name:
string)
Reports whether a given encoding is available.
Parameter | Type | Description |
---|---|---|
name | string | The encoding name. Typical values are "ASCII", "binary", or "UTF-8". For a complete list of supported encodings, see the JavaScript Tools Guide. |
File openDialog (prompt:
string[, filter:
any=null][, multiSelect:
bool=false])
Opens a dialog so the user can select one or more files to open.
Opens the built-in platform-specific file-browsing dialog in which a user can select an existing file or multiple files, and creates new File objects to represent the selected files.
• If the user clicks OK, returns a File object for the selected file, or an array of objects if multiple files are selected.
• If the user cancels, returns null.
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) • In Windows, a filter expression such as "Javascript files:*.jsx;All files:*.*". • In Mac OS, a filter function that takes a File instance and returns true if the file should be included in the display, false if it should not. (Optional) |
multiSelect | bool | When true, the user can select multiple files and the return value is an array. (default: false) (Optional) |
File saveDialog (prompt:
string[, filter:
any=null])
Opens a dialog so the user can select a file name to save to.
Opens the built-in platform-specific file-browsing dialog in which a user can select an existing file location to which to save information, and creates a new File object to represent the selected file location.
• If the user clicks OK, returns a File object for the selected file location.
• If the user cancels, returns null.
Parameter | Type | Description |
---|---|---|
prompt | string | The prompt text, displayed if the dialog allows a prompt. |
filter | any | In Windows only, a filter that limits the types of files displayed in the dialog. (default: null) In Windows only, a filter expression such as "Javascript files:*.jsx;All files:*.*". Not used In Mac OS. (Optional) |
Instances
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. |
Example | file.changePath (".."); |
bool close ()
Closes this open file.
Returns true if the file was closed successfully, false if an I/O error occurred.
Example | aFile.close() |
bool copy (target:
string | File)
Copies this object's referenced file to the specified target location.
Resolves any aliases to find the source file. If a file exists at the target location, it is overwritten.
Returns true if the copy was successful.
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. |
Example | aFile.copy(target) |
void createAlias (path:
string)
Makes this file a file-system alias or shortcut to the specified file.
The referenced file for this object must not yet exist on disk. Returns true if the operation was successful.
Parameter | Type | Description |
---|---|---|
path | string | A string containing the path of the target file. |
bool execute ()
Executes or opens this file using the appropriate application, as if it had been double-clicked in a file browser.
You can use this method to run scripts, launch applications, and so on.
Returns true immediately if the application launch was successful.
string getRelativeURI (basePath:
string)
Retrieves and returns the path for this file, relative to the specified base path, in URI notation.
If no base path is supplied, the URI is relative to the path of the current folder. Returns a string containing the relative URI.
Parameter | Type | Description |
---|---|---|
basePath | string | A base path in URI notation. |
Example | aFile.getRelativeURI(basePath) |
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.
Returns true if the file was opened successfully.
The method attempts to detect the encoding of the open file. It reads a few bytes at the current location and tries to detect the Byte Order Mark character 0xFFFE. If found, the current position is advanced behind the detected character and the encoding property is set to one of the strings UCS-2BE, UCS-2LE, UCS4-BE, UCS-4LE, or UTF-8. If the marker character is not found, it checks for zero bytes at the current location and makes an assumption about one of the above formats (except UTF-8). If everything fails, the encoding property is set to the system encoding.
IMPORTANT: Be careful about opening a file more than once. The operating system usually permits you to do so, but if you start writing to the file using two different File objects, you can destroy your data.
Parameter | Type | Description |
---|---|---|
mode | string | The read-write mode, a single-character string. One of these characters: • r (read) Opens for reading. If the file does not exist or cannot be found, the call fails. • w (write) Opens a file for writing. If the file exists, its contents are destroyed. If the file does not exist, creates a new, empty file. • e (edit) Opens an existing file for reading and writing. • a (append) Opens an existing file for reading and writing, and moves the current position to the end of the file. |
type | string | In Mac OS, the type of a newly created file, a 4-character string. Ignored in Windows and UNIX. (Optional) |
creator | string | In Mac OS, the creator of a newly created file, a 4-character string. Ignored in Windows and UNIX. (Optional) |
Example | aFile.open(mode, type, creator) |
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.
Differs from the class method openDialog() in that it presets the current folder to this File object's parent folder and the current file to this object's associated file.
• If the user clicks OK, returns a File or Folder object for the selected file or folder, or an array of objects.
• If the user cancels, returns null.
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) • In Windows, a filter expression such as "Javascript files:*.jsx;All files:*.*". • In Mac OS, a filter function that takes a File instance and returns true if the file should be included in the display, false if it should not. (Optional) |
multiSelect | bool | When true, the user can select multiple files and the return value is an array. (default: false) (Optional) |
string read ([chars:
number])
Reads the contents of the file, starting at the current position.
Returns a string that contains up to the specified number of characters. If a number of characters is not supplied, reads from the current position to the end of the file. If the file is encoded, multiple bytes might be read to create single Unicode characters.
Parameter | Type | Description |
---|---|---|
chars | number | An integer specifying the number of characters to read. (Optional) |
Example | aFile.read(chars) |
string readch ()
Reads a single text character from the file at the current position.
Line feeds are recognized as CR, LF, CRLF or LFCR pairs. If the file is encoded, multiple bytes might be read to create a single Unicode character. Returns a string that contains the character.
Example | aFile.readch() |
string readln ()
Reads a single line of text from the file at the current position.
Line feeds are recognized as CR, LF, CRLF or LFCR pairs.. If the file is encoded, multiple bytes might be read to create single Unicode characters. Returns a string that contains the text.
Example | aFile.readln() |
bool remove ()
Deletes the file associated with this object from disk immediately, without moving it to the system trash.
Does not resolve aliases; instead, deletes the referenced alias or shortcut file itself. Returns true if the file was successfully removed.
• IMPORTANT: Cannot be undone. It is recommended that you prompt the user for permission before deleting.
bool rename (newName:
string)
Renames the associated file.
Does not resolve aliases, but renames the referenced alias or shortcut file itself. Returns true if the file was successfully renamed.
Parameter | Type | Description |
---|---|---|
newName | string | The new file name, with no path information. |
Example | aFile.rename(newName) |
File resolve ()
Attempts to resolve the file-system alias or shortcut that this object refers to.
If successful, creates and returns a new File object that points to the resolved file system element. Returns null if this object does not refer to an alias, or if the alias could not be resolved.
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.
Differs from the class method saveDialog() in that it presets the current folder to this File object's parent folder and the file to this object's associated file.
• If the user clicks OK, returns a File object for the selected file.
• If the user cancels, returns null.
Parameter | Type | Description |
---|---|---|
prompt | string | A string containing the prompt text, if the dialog allows a prompt. |
filter | any | In Windows only, a filter that limits the types of files displayed in the dialog. (default: null) In Windows only, a filter expression such as "Javascript files:*.jsx;All files:*.*". Not used In Mac OS. (Optional) |
bool seek (pos:
number[, mode:
number=0])
Seeks to a given position in the file.
The new position cannot be less than 0 or greater than the current file size. Returns true if the position was changed.
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 (range: 0 - 2) | The seek mode. (default: 0) One of: • 0: Seek to absolute position, where pos=0 is the first byte of the file. This is the default. • 1: Seek relative to the current position. • 2. Seek backward from the end of the file. (Optional) |
Example | aFile.seek(pos, mode) |
number tell ()
Retrieves the current position as a byte offset from the start of the file.
Returns a number, the position index.
Example | aFile.tell() |
string toSource ()
Creates and returns a serialized string representation of this object.
Pass the resulting string to eval() to recreate the object.
string toString ()
Converts this object to a string.
bool write (text:
string)
Writes the specified text to the file at the current position.
You can supply multiple text values; the strings are concatenated to form a single string.
For encoded files, writing a single Unicode character may write multiple bytes. Returns true if the write was successful.
IMPORTANT: Be careful not to write to a file that is open in another application or object, as this can overwrite existing data.
Parameter | Type | Description |
---|---|---|
text | string | A text string to be written. |
Example | aFile.write(text, ...) |
bool writeln (text:
string)
Writes a string to the file at the current position and appends a line-feed sequence.
You can supply multiple text values. The strings are concatenated into a single string, which is written in the file followed by one line-feed sequence, of the style specified by this object's linefeed property.
For encoded files, writing a single Unicode character may write multiple bytes. Returns true if the write was successful.
IMPORTANT: Be careful not to write to a file that is open in another application or object, as this can overwrite existing data.
Parameter | Type | Description |
---|---|---|
text | string | A text string to be written. |
Example | aFile.writeln(text, ...) |
Element of
Application.colorSettingsList
Application.defaultColorSettings
Application.path
Document.fullName
Document.path
PPDFileInfo.PPDFilePath
PlacedItem.file
PrintJobOptions.file
RasterItem.file
Reflection.sampleFile
ReflectionInfo.sampleFile
Used in:
any $.evalFile (file: File[, timeout: number=10000])
void Application.aATExecuteSessionFromFile (file: File)
bool Application.dumpPGFFile (file: File[, documentColorSpace: DocumentColorSpace], pGFFile: File)
void Application.loadAction (actionFilePath: File)
void Application.loadColorSettings (fileSpec: File)
Document Application.open (file: File[, documentColorSpace: DocumentColorSpace][, options: any])
void Application.reflectCSAW (outputFolder: File)
array of string Application.showPresets (fileSpec: File)
void Document.exportFile (exportFile: File, exportFormat: ExportType[, options: any])
void Document.exportPDFPreset (file: File)
void Document.exportPerspectiveGridPreset (file: File)
void Document.exportPrintPreset (file: File)
void Document.exportVariables (file: File)
void Document.imageCapture (imageFile: File[, clipBounds: Rectangle][, options: ImageCaptureOptions])
void Document.importCharacterStyles (fileSpec: File)
void Document.importPDFPreset (fileSpec: File[, replacingPreset: bool=false])
void Document.importParagraphStyles (fileSpec: File)
void Document.importPerspectiveGridPreset (fileSpec: File[, perspectivePreset: string])
void Document.importPrintPreset (printPreset: string, fileSpec: File)
void Document.importVariables (fileSpec: File)
void Document.saveAs (saveIn: File[, options: any])
void Document.windowCapture (imageFile: File, windowSize: Point)
bool File.copy (target: string | File)
void FlashPlayer.loadMovie (file: File)
GroupItem GroupItems.createFromFile (imageFile: File)
void PlacedItem.relink (fileSpec: File)
Return
File Application.aATGetEditorDialogFile ()
File Application.aATGetErrorDialogFile ()
File Application.getPresetFileOfType (presetType: DocumentPresetType)
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])
Jongware, 25-Nov-2012 v3.0.3i | Contents :: Index |