1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is Mozilla Communicator client code, released
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998-1999
21 * the Initial Developer. All Rights Reserved.
24 * Doug Turner <dougt@netscape.com>
25 * Christopher Blizzard <blizzard@mozilla.org>
26 * Darin Fisher <darin@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either of the GNU General Public License Version 2 or later (the "GPL"),
30 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #include
"nsISupports.idl"
44 interface nsISimpleEnumerator
;
47 * This is the only correct cross-platform way to specify a file.
48 * Strings are not such a way. If you grew up on windows or unix, you
49 * may think they are. Welcome to reality.
51 * All methods with string parameters have two forms. The preferred
52 * form operates on UCS-2 encoded characters strings. An alternate
53 * form operates on characters strings encoded in the "native" charset.
55 * A string containing characters encoded in the native charset cannot
56 * be safely passed to javascript via xpconnect. Therefore, the "native
57 * methods" are not scriptable.
61 [scriptable
, uuid(c8c0a080
-0868-11d3
-915f
-d9d889d48e3c
)]
62 interface nsIFile
: nsISupports
67 * NORMAL_FILE_TYPE - A normal file.
68 * DIRECTORY_TYPE - A directory/folder.
70 const unsigned long NORMAL_FILE_TYPE
= 0;
71 const unsigned long DIRECTORY_TYPE
= 1;
76 * This function is used for constructing a descendent of the
80 * A string which is intended to be a child node of the nsIFile.
81 * For the |appendNative| method, the node must be in the native
84 void append
(in AString node
);
85 [noscript
] void appendNative
(in ACString node
);
88 * Normalize the pathName (e.g. removing .. and . components on Unix).
95 * This function will create a new file or directory in the
96 * file system. Any nodes that have not been created or
97 * resolved, will be. If the file or directory already
98 * exists create() will return NS_ERROR_FILE_ALREADY_EXISTS.
101 * This specifies the type of file system object
102 * to be made. The only two types at this time
103 * are file and directory which are defined above.
104 * If the type is unrecongnized, we will return an
105 * error (NS_ERROR_FILE_UNKNOWN_TYPE).
108 * The unix style octal permissions. This may
109 * be ignored on systems that do not need to do
112 void create
(in unsigned long type
, in unsigned long permissions
);
115 * Accessor to the leaf name of the file itself.
116 * For the |nativeLeafName| method, the nativeLeafName must
117 * be in the native filesystem charset.
119 attribute AString leafName
;
120 [noscript
] attribute ACString nativeLeafName
;
125 * This will copy this file to the specified newParentDir.
126 * If a newName is specified, the file will be renamed.
127 * If 'this' is not created we will return an error
128 * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
130 * copyTo may fail if the file already exists in the destination
133 * copyTo will NOT resolve aliases/shortcuts during the copy.
135 * @param newParentDir
136 * This param is the destination directory. If the
137 * newParentDir is null, copyTo() will use the parent
138 * directory of this file. If the newParentDir is not
139 * empty and is not a directory, an error will be
140 * returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the
141 * |CopyToNative| method, the newName must be in the
142 * native filesystem charset.
145 * This param allows you to specify a new name for
146 * the file to be copied. This param may be empty, in
147 * which case the current leaf name will be used.
149 void copyTo
(in nsIFile newParentDir
, in AString newName
);
150 [noscript
] void CopyToNative
(in nsIFile newParentDir
, in ACString newName
);
153 * copyToFollowingLinks[Native]
155 * This function is identical to copyTo with the exception that,
156 * as the name implies, it follows symbolic links. The XP_UNIX
157 * implementation always follow symbolic links when copying. For
158 * the |CopyToFollowingLinks| method, the newName must be in the
159 * native filesystem charset.
161 void copyToFollowingLinks
(in nsIFile newParentDir
, in AString newName
);
162 [noscript
] void copyToFollowingLinksNative
(in nsIFile newParentDir
, in ACString newName
);
167 * A method to move this file or directory to newParentDir.
168 * If a newName is specified, the file or directory will be renamed.
169 * If 'this' is not created we will return an error
170 * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
171 * If 'this' is a file, and the destination file already exists, moveTo
172 * will replace the old file.
174 * moveTo will NOT resolve aliases/shortcuts during the copy.
175 * moveTo will do the right thing and allow copies across volumes.
176 * moveTo will return an error (NS_ERROR_FILE_DIR_NOT_EMPTY) if 'this' is
177 * a directory and the destination directory is not empty.
178 * moveTo will return an error (NS_ERROR_FILE_ACCESS_DENIED) if 'this' is
179 * a directory and the destination directory is not writable.
181 * @param newParentDir
182 * This param is the destination directory. If the
183 * newParentDir is empty, moveTo() will rename the file
184 * within its current directory. If the newParentDir is
185 * not empty and does not name a directory, an error will
186 * be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For
187 * the |moveToNative| method, the newName must be in the
188 * native filesystem charset.
191 * This param allows you to specify a new name for
192 * the file to be moved. This param may be empty, in
193 * which case the current leaf name will be used.
195 void moveTo
(in nsIFile newParentDir
, in AString newName
);
196 [noscript
] void moveToNative
(in nsIFile newParentDir
, in ACString newName
);
199 * This will try to delete this file. The 'recursive' flag
200 * must be PR_TRUE to delete directories which are not empty.
202 * This will not resolve any symlinks.
204 void remove
(in boolean recursive
);
207 * Attributes of nsIFile.
210 attribute
unsigned long permissions
;
211 attribute
unsigned long permissionsOfLink
;
214 * File Times are to be in milliseconds from
215 * midnight (00:00:00), January 1, 1970 Greenwich Mean
218 attribute PRInt64 lastModifiedTime
;
219 attribute PRInt64 lastModifiedTimeOfLink
;
222 * WARNING! On the Mac, getting/setting the file size with nsIFile
223 * only deals with the size of the data fork. If you need to
224 * know the size of the combined data and resource forks use the
225 * GetFileSizeWithResFork() method defined on nsILocalFileMac.
227 attribute PRInt64 fileSize
;
228 readonly attribute PRInt64 fileSizeOfLink
;
233 * Accessor to the string path. The native version of these
234 * strings are not guaranteed to be a usable path to pass to
235 * NSPR or the C stdlib. There are problems that affect
236 * platforms on which a path does not fully specify a file
237 * because two volumes can have the same name (e.g., mac).
238 * This is solved by holding "private", native data in the
239 * nsIFile implementation. This native data is lost when
240 * you convert to a string.
242 * DO NOT PASS TO USE WITH NSPR OR STDLIB!
245 * Find out what the symlink points at. Will give error
246 * (NS_ERROR_FILE_INVALID_PATH) if not a symlink.
249 * Find out what the nsIFile points at.
251 * Note that the ACString attributes are returned in the
252 * native filesystem charset.
255 readonly attribute AString target
;
256 [noscript
] readonly attribute ACString nativeTarget
;
257 readonly attribute AString path
;
258 [noscript
] readonly attribute ACString nativePath
;
261 boolean isWritable
();
262 boolean isReadable
();
263 boolean isExecutable
();
265 boolean isDirectory
();
269 * Not a regular file, not a directory, not a symlink.
276 * This function will create a new file or directory in the
277 * file system. Any nodes that have not been created or
278 * resolved, will be. If this file already exists, we try
279 * variations on the leaf name "suggestedName" until we find
280 * one that did not already exist.
282 * If the search for nonexistent files takes too long
283 * (thousands of the variants already exist), we give up and
284 * return NS_ERROR_FILE_TOO_BIG.
287 * This specifies the type of file system object
288 * to be made. The only two types at this time
289 * are file and directory which are defined above.
290 * If the type is unrecongnized, we will return an
291 * error (NS_ERROR_FILE_UNKNOWN_TYPE).
294 * The unix style octal permissions. This may
295 * be ignored on systems that do not need to do
298 void createUnique
(in unsigned long type
, in unsigned long permissions
);
303 * This function will allocate and initialize a nsIFile object to the
304 * exact location of the |this| nsIFile.
307 * A nsIFile which this object will be initialize
314 * Will determine if the inFile equals this.
316 boolean equals
(in nsIFile inFile
);
319 * Will determine if inFile is a descendant of this file
320 * If |recur| is true, look in subdirectories too
322 boolean contains
(in nsIFile inFile
, in boolean recur
);
325 * Parent will be null when this is at the top of the volume.
327 readonly attribute nsIFile parent
;
330 * Returns an enumeration of the elements in a directory. Each
331 * element in the enumeration is an nsIFile.
333 * @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
334 * not specify a directory.
336 readonly attribute nsISimpleEnumerator directoryEntries
;
340 #ifdef MOZILLA_INTERNAL_API
341 #include
"nsDirectoryServiceUtils.h"