You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.

nsIFile
This interface is the only correct cross-platform way to specify a file. Strings are not such a way. Despite the fact that they work on Windows or Unix, they will not work here.
All methods with string parameters have two forms. The preferred form operates on UCS-2 encoded characters strings. An alternate form operates on characters strings encoded in the "native" charset. A string containing characters encoded in the native charset cannot be safely passed to JavaScript via XPConnect. Therefore, the UCS-2 forms are scriptable, but the "native" methods are not.
Makes a descendent of the current
nsIFile.Syntax:
void nsIFile::append(in AString node) [noscript] void nsIFile::appendNative(in ACString node)Parameters:
node: A string which is intended to be a child node of thensIFile. For theappendNativemethod, the node must be in the native filesystem charset.
nsresult:
Normalizes the pathName (e.g. removing .. and . components on Unix).
Syntax:
void nsIFile::normalize()Parameters:
nsresult:
Creates a new file or directory in the file system. Any nodes that have not been created or resolved, will be. If the file or directory already exists, create returns
NS_ERROR_FILE_ALREADY_EXISTS.Syntax:
void nsIFile::create(in unsigned long type, in unsigned long permissions)Parameters:
type: This specifies the type of file system object to be made. The only two types at this time are file and directory which are defined below. If the type is unrecognized, returns (NS_ERROR_FILE_UNKNOWN_TYPE).
permissions: Unix style octal permissions. This may be ignored on systems that do not need to do permissions.
nsresult:
Copies this file to the specified newParentDir. If a newName is specified, the file will be renamed. If 'this' is not created, returns the error (
NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).copyTomay fail if the file already exists in the destination directory.copyTowill NOT resolve aliases/shortcuts during the copy.Syntax:
void nsIFile::copyTo(in nsIFile newParentDir, in AString newName) [noscript] void nsIFile::CopyToNative( in nsIFile newParentDir, in ACString newName)Parameters:
newParentDir: The destination directory. If thenewParentDiris empty,copyTowill use the parent directory of this file. If thenewParentDiris not empty and is not a directory, an error will be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For theCopyToNativemethod, thenewNamemust be in the native filesystem charset.
newName: This param allows you to specify a new name for the file to be copied. This param may be empty, in which case the current leaf name will be used.
nsresult:
Is identical to
copyToexcept, as the name implies, it follows symbolic links. The XP_UNIX implementation always follows symbolic links when copying.Syntax:
void nsIFile::copyToFollowingLinks( in nsIFile newParentDir, in AString newName) {noscript] void nsIFile::copyToFollowingLinksNative( in nsIFile newParentDir, in ACString newName)Parameters:
newParentDir: The destination directory. If thenewParentDiris empty,copyTowill use the parent directory of this file. If thenewParentDiris not empty and is not a directory, an error will be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR).
newName: This param allows you to specify a new name for the file to be copied. This param may be empty, in which case the current leaf name will be used. For thecopyToFollowingLinksNativemethod, thenewNamemust be in the native filesystem charset.
nsresult:
Moves this file to the specified
newParentDir. If anewNameis specified, the file will be renamed. If 'this' is not created, returns an error (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).moveTowill NOT resolve aliases/shortcuts during the copy.moveTowill do the right thing and allow copies across volumes.Syntax:
void nsIFile::moveTo(in nsIFile newParentDir, in AString newName) [noscript] void nsIFile::moveToNative( in nsIFile newParentDir, in ACString newName)Parameters:
newParentDir: This param is the destination directory. If thenewParentDiris empty,moveTowill rename the file within its current directory. If thenewParentDiris not empty and does not name a directory, an error will be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For themoveToNativemethod, the newName must be in the native filesystem charset.
newName: This param allows you to specify a new name for the file to be moved. This param may be empty, in which case the current leaf name will be used. For themoveToNativemethod, thenewNamemust be in the native filesystem charset.
nsresult:
Tries to delete this file. The 'recursive' flag must be
PR_TRUEto delete directories which are not empty. It will not resolve any symlinks.Syntax:
void nsIFile::remove(in boolean recursive)Parameters:
nsresult:
Determines if this file exists.
Syntax:
boolean nsIFile::exists()Parameters:
Returns:
Determines if this file is writable.
Syntax:
boolean nsIFile::isWritable()Parameters:
Returns:
Determines if this file is readable.
Syntax:
boolean nsIFile::isReadable()Parameters:
Returns:
Determines if this file is executable.
Syntax:
boolean nsIFile::isExecutable()Parameters:
Returns:
Determines if this file is hidden.
Syntax:
boolean nsIFile::isHidden()Parameters:
Returns:
Determines if this file is a directory.
Syntax:
boolean nsIFile::isDirectory()Parameters:
Returns:
Determines if this file is a file.
Syntax:
boolean nsIFile::isFile()Parameters:
Returns:
Determines if this file is a symbolic link.
Syntax:
boolean nsIFile::isSymlink()Parameters:
Returns:
Determines if this file is other than a regular file, a directory, or a symbolic link.
Syntax:
boolean nsIFile::isSpecial()Parameters:
Returns:
Create a new file or directory in the file system. Any nodes that have not been created or resolved, will be. If this file already exists, this method tries variations on the leaf name "suggestedName" until it finds one that does not already exist. If the search for nonexistent files takes too long (thousands of the variants already exist), it gives up and return
NS_ERROR_FILE_TOO_BIG.Syntax:
void nsIFile::createUnique(in unsigned long type, in unsigned long permissions)Parameters:
type: The type of file system object to be made. The only two types at this time are file and directory which are defined below. If the type is unrecongnized, returns an error (NS_ERROR_FILE_UNKNOWN_TYPE).
permissions: Unix style octal permissions. This may be ignored on systems that do not need to do permissions.
nsresult:
Allocates and initializes an
nsIFileobject to the exact location ofthisnsIFileSyntax:
nsIFile nsIFile::clone()Parameters:
Returns:
Determines if
inFileequals a comparison object.Syntax:
boolean nsIFile::equals(in nsIFile inFile)Parameters:
Returns:
Determines if
inFileis a descendant of this file. IfrecurisTRUE, it will also look in subdirectories.Syntax:
boolean nsIFile::contains(in nsIFile inFile, in boolean recur)Parameters:
Returns:
Gets and sets the leaf name of the file itself.
nativeLeafNamemust be in the native filesystem charset.Gets and sets permissions status.
Gets and set permissions of link status.
Gets and sets time of the last file modification. Times are stored as milliseconds from midnight (00:00:00), January 1, 1970 Greenwich Mean Time (GMT).
Gets and sets time of the last symlink modification.Times are stored as milliseconds from midnight (00:00:00), January 1, 1970 Greenwich Mean Time (GMT).
Warning: On the Mac, getting/setting the file size with
nsIFileonly deals with the size of the data fork. If you need to know the size of the combined data and resource forks use theGetFileSizeWithResForkmethod defined onnsILocalFileMac..Gets the target, ie, what the symlink points at. Gives an error (NS_ERROR_FILE_INVALID_PATH) if not a symlink. Note that the ACString attribute is returned in the native filesystem charset.
Warning:The native version of these strings are not guaranteed to be a usable path to pass to NSPR or the C stdlib. There are problems that affect platforms on which a path does not fully specify a file because two volumes can have the same name (e.g., XP_MAC). This is solved by holding "private", native data in the
nsIFileimplementation. This native data is lost when you convert to a string.DO NOT USE TO PASS TO NSPR OR STDLIB!
Gets the path, ie, what the
nsIFilepoints at. In the native version, the ACString is returned in the native filesystem charset.Warning:The native version of these strings are not guaranteed to be a usable path to pass to NSPR or the C stdlib. There are problems that affect platforms on which a path does not fully specify a file because two volumes can have the same name (e.g., XP_MAC). This is solved by holding "private", native data in the
nsIFileimplementation. This native data is lost when you convert to a string.DO NOT USE TO PASS TO NSPR OR STDLIB!
Gets the parent of this file. Parent will be
nullwhen this file is at the top of the volume.Gets an enumeration of the elements in a directory. Each element in the enumerator is an
nsIFile. If the currentnsIFiledoes not specify a dirctory, returns an errorNS_ERROR_FILE_NOT_DIRECTORY.Constants for
typeparameters.NORMAL_FILE_TYPEis a normal file andDIRECTORY_TYPEis a directory/folder.
| Written by:Ellen Evans | Comments, questions, complaints?
Bug 143387 |