Files object

The following table lists the methods of the Files object, along with their data types and, where appropriate, acceptable values and notes.

Method Data type Notes

copy(docname1, docname2)

string, string

Copies the file specified in the first argument to the file specified in the second argument. Each argument must be the name of a file, which is expressed as file://URL. Only files (not directories) can be copied. The files do not need to reside on the same drive, and the method does not overwrite a file if it already exists. Returns a value of true if the copy is successful; false otherwise.

createDirectory(dirname)

string

Creates the specified directory. Returns true if successful; false otherwise.

createFile(fileURL, fileType, fileCreator)

string, string, string

Creates the specified file. The file must not already exist. The first argument is the name of the file, which is expressed as file://URL. The last two arguments let you specify the file type and file creator strings. The fileType and fileCreator strings should each be strings of exactly four characters in length, for example:

Files.createFile(newFile,".txt","FWMX");

deleteFile(docOrDir)

string

Deletes the specified file or directory. Returns true if successful; false if the file or directory does not exist or cannot be deleted. Compare with deleteFileIfExisting().

deleteFileIfExisting (docOrDir)

string

Deletes the specified file or directory. Returns true if successful; false if the file or directory cannot be deleted. Unlike deleteFile(), this method returns true if the file or directory does not exist.

enumFiles(docOrDir)

string

Returns an array of file URLs. If docOrDir is a directory, the array contains an entry for every file or directory that is contained in the specified directory. If docOrDir is a file, the array contains a single entry (the file passed in).

exists(docOrDir)

string

Returns true if docOrDir refers to a directory or file that exists; false otherwise.

getDirectory(docname)

string

Returns only the directory name from docname, which is expressed as file://URL. For example, Files.getDirectory("file://work/logo.png") returns "file:///work".

getExtension(docname)

string

Returns the filename extension, if any, of docname. For example, Files.getExtension("birthday.png") returns ".png". If the filename has no extension, an empty string is returned. A filename that is expressed as file://URL is acceptable.

getFilename(docname)

string

Returns just the filename from docname, which is expressed as file://URL. For example, Files.getFilename("file:///work/logo.png") returns "logo.png".

getLanguageDirectory()

string

Returns the URL of the language directory associated with the currently running language.

getLastErrorString()

none

If the last call to a method in a Files object resulted in an error, returns a string that describes the error. If the last call succeeded, returns null.

getTempFilePath ({dirname})

string

The argument, if used, must be expressed as file://URL. Returns a file URL in the Temporary Files directory or in the specified directory. This method does not create a file; it simply returns a unique file URL that does not conflict with existing files in the directory. If dirname is passed and is not null, the URL that is returned indicates a file in the specified directory rather than in the Temporary Files directory.

isDirectory(dirname)

string

The argument must be expressed as file://URL. Returns true if the specified URL refers to a directory that exists; false otherwise.

makePathFromDirAndFile(dirname, plainFilename)

string, string

The first argument must be expressed as file://URL. Concatenates the two arguments to return a file URL that references the specified filename in the specified directory. For example, Files.makePathFromDirAndFile("file:///work/reports", "logo.png") returns "file:///work/reports/logo.png".

open(docname, bWrite)

string, Boolean

The first argument must be expressed as file://URL. Opens the specified file for reading or writing. If the second argument is true, the file opens for writing; otherwise it opens for reading. If the file cannot be opened, returns null; otherwise, returns a File Reference object.

rename(docname, newPlainFilename)

string, string

The docname argument is a file path or a file URL to the file that you want to rename.

The newPlainFilename argument is the new name to assign to the file.

The rename method returns a URL path of the newly renamed file if successful; otherwise Fireworks returns null.

setFilename(docname, newPlainFilename)

string, string

The first argument must be expressed as file://URL. Returns a file URL with docname replaced by newPlainFilename. For example, Files.setFilename("file:///work/logo.png", "oldlogo.png") returns "file:///work/oldlogo.png". This method does not affect the file on disk; it simply provides a convenient way to manipulate file URLs. To change the name on disk, use rename().

swap(docname1, docname2)

string, string

Each argument must be expressed as a file://URL. Swaps the contents of the two specified files, so that each file contains the contents of the other file. Only files (not directories) can be swapped, and both files must reside on the same drive. Returns true if the swap is successful; false otherwise.

File Reference object

The File Reference object is used to refer to a specific open file. The following table lists the methods of the File Reference object, along with their data types and, where appropriate, acceptable values and notes.

Method Data Type Notes

close()

none

Closes the current File Reference object. You are not required to use this method (the file is closed when the Files object is destroyed), but it is useful for controlling access to a file.

readline()

none

Reads the next line from the current File Reference object and returns it as a string. The end-of-line character(s) are not included in the string. Returns null if end-of-file is reached or if the line is longer than 2048 characters.

write(textString)

string

Writes the specified string to the current File Reference object. No end-of-line characters are appended; to include one, use "\n".


 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/fireworks/8/fwextending/fw_02_19.htm