Adobe InDesign CS5.5 (7.5) Object Model JS: Folder

InDesign CS5.5

Class

Folder

 Represents a file-system folder or directory in a platform-independent manner.

QuickLinks

Folder, changePath, create, decode, encode, execute, getFiles, getRelativeURI, isEncodingAvailable, remove, rename, resolve, selectDialog, selectDlg, toSource, toString

Hierarchy

Folder
Folder
File | Folder

Properties

PropertyTypeAccessDescription
absoluteURIstring readonlyThe full path name for the referenced folder in URI notation.
aliasbool readonlyWhen true, the object refers to a file system alias or shortcut.
createdDate readonlyThe creation date of the referenced folder, or null if the object does not refer to a folder on disk.
displayNamestring readonlyThe localized name portion of the absolute URI for the referenced folder, without the path specification.
errorstring r/wA 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.
existsbool readonlyWhen true, this object refers to a folder that currently exists in the file system.
fsNamestring readonlyThe platform-specific name of the referenced folder as a full path name.
fullNamestring readonlyThe full path name for the referenced folder in URI notation. .
modifiedDate readonlyThe date of the referenced folder's last modification, or null if the object does not refer to a folder on disk.
namestring readonlyThe folder name portion of the absolute URI for the referenced file, without the path specification.
parentFolder readonlyTThe Folder object for the folder that contains this folder, or null if this object refers to the root folder of a volume.
pathstring readonlyThe path portion of the object absolute URI for the referenced file, without the folder name.
relativeURIstring readonlyThe path name for the referenced folder in URI notation, relative to the current folder.

Class

PropertyTypeAccessDescription
appDataFolder readonlyThe folder containing the application data for all users.

• In Windows, the value of %APPDATA% (by default, C:\\Documents and Settings\\All Users\\Application Data)
• In Mac OS, /Library/Application Support
appPackageFolder readonlyIn Mac OS, a Folder object for the folder containing the bundle of the running application.
commonFilesFolder readonlyA Folder object for the folder containing common files for all programs installed by the user.

• In Windows, the value of %CommonProgramFiles% (by default, C:\\Program Files\\Common Files)
• In Mac OS, /Library/Application Support
currentFolder r/wA Folder object for the current folder.
Assign a Folder object or a string containing the new path name to set the current folder. This is a class property accessed through the Folder constructor.
desktopFolder readonlyA Folder object for the folder that contains the user’s desktop.

• In Windows, C:\\Documents and Settings\\username\\Desktop
• In Mac OS, ~/Desktop
fsstring readonlyThe name of the current file system.
One of "Windows", "Macintosh", or "Unix".
myDocumentsFolder readonlyA folder pointing to the user's My Documents folder.

• In Windows, C:\\Documents and Settings\\username\\My Documents
• In Mac OS, ~/Documents
startupFolder readonlyA Folder object for the folder containing the executable image of the running application.
systemFolder readonlyA Folder object for the folder containing the operating system files.

• In Windows, the value of %windir% (by default, C:\\Windows)
• In Mac OS, /System
tempFolder readonlyA Folder object for the default folder for temporary files.
trashFolder readonlyA Folder object for the folder containing deleted items. On Windows, the trash folder is a virtual folder containing a database; therefore, the property value is null on Windows.
userDataFolder readonlyA Folder object for the folder containing the user's application data.

•  In Windows, the value of %USERDATA% (by default, C:\\Documents and Settings\\username\\Application Data)
• In Mac OS, ~/Library/Application Support.

Methods

Constructor

Folder Folder ([path: string])
Creates and returns a new Folder object referring to a given file-system location.
If the path name refers to an already existing disk file, a File object is returned instead. Returns the new Folder object.

ParameterTypeDescription
pathstringThe absolute or relative path to the folder associated with this object, specified in URI format.
The value stored in the object is the absolute path.The path need not refer to an existing folder. If the path refers to an existing file, rather than a folder:
•  The Folder() function returns a File object instead of a Folder object.
•  The new operator returns a Folder object for a nonexisting folder with the same name. (Optional)

Examplenew Folder(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().

ParameterTypeDescription
uristringThe UTF-8 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().

ParameterTypeDescription
namestringThe string to encode.

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

ParameterTypeDescription
namestringThe encoding name.
Typical values are "ASCII", "binary", or "UTF-8". For a complete list of supported encodings, see the JavaScript Tools Guide.

Folder selectDialog (prompt: string)
Opens the built-in platform-specific file-browsing dialog, and creates a new File or Folder object for the selected file or folder.
Differs from the object method selectDlg() in that it does not preselect a folder.
• If the user clicks OK, returns a File or Folder object for the selected file or folder.
• If the user cancels, returns null.

ParameterTypeDescription
promptstringThe prompt text, if the dialog allows a prompt.

Instances

bool changePath (path: string)
Changes the path specification of the referenced folder.

ParameterTypeDescription
pathstringA string containing the new path, absolute or relative to the current folder.

Examplefolder.changePath ("..");

bool create ()
Creates a folder at the location given by this object's path property.
Returns true if the folder was created.

ExampleaFolder.create()

bool execute ()
Opens this folder in the platform-specific file browser (as if it had been double-clicked in the file browser).
Returns true immediately if the folder was opened successfully.

Array getFiles (mask: any)
Retrieves the contents of this folder, filtered by the supplied mask.
Returns an array of File and Folder objects, or null if this object's referenced folder does not exist.

ParameterTypeDescription
mask any A search mask for file names, specified as a string or a function.
A mask string can contain question mark (?) and asterisk (*) wild cards. Default is "*", which matches all file names.
Can also be the name of a function that takes a File or Folder object as its argument. It is called for each file or folder found in the search; if it returns true, the object is added to the return array.
• NOTE: In Windows, all aliases end with the extension .lnk. ExtendScript strips this from the file name when found, in order to preserve compatibility with other operating systems. You can search for all aliases by supplying the search mask "*.lnk", but note that such code is not portable.

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.

ParameterTypeDescription
basePathstringA base path in URI notation. (default: .) (Optional)

ExampleaFile.getRelativeURI(basePath)

bool remove ()
Deletes the folder associated with this object from disk immediately, without moving it to the system trash.
Folders must be empty before they can be deleted. 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 folder.
Does not resolve aliases, but renames the referenced alias or shortcut file itself. Returns true if the folder was successfully renamed.

ParameterTypeDescription
newNamestringThe new folder name, with no path information.

ExampleaFolder.rename(newName)

Folder resolve ()
Attempts to resolve the file-system alias or shortcut that this object refers to.
If successful, creates and returns a new Folder 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.

ExampleaFolder.resolve()

Folder selectDlg (prompt: string)
Opens the built-in platform-specific file-browsing dialog, and creates a new File or Folder object for the selected file or folder.
Differs from the class method selectDialog() in that it preselects this folder.
• If the user clicks OK, returns a File or Folder object for the selected file or folder.
• If the user cancels, returns null.

ParameterTypeDescription
promptstringThe prompt text, if the dialog allows a prompt.

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.

Element of

File.parent

Folder.appData

Folder.appPackage

Folder.commonFiles

Folder.current

Folder.desktop

Folder.myDocuments

Folder.parent

Folder.startup

Folder.system

Folder.temp

Folder.trash

Folder.userData

Return

Folder Folder.Folder ([path: string])

Folder Folder.resolve ()

Folder Folder.selectDialog (prompt: string)

Folder Folder.selectDlg (prompt: string)

Jongware, 28-Apr-2012 v3.0.3iContents :: Index