nsIFile.idl 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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
  4. *
  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/
  9. *
  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
  13. * License.
  14. *
  15. * The Original Code is Mozilla Communicator client code, released
  16. * March 31, 1998.
  17. *
  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.
  22. *
  23. * Contributor(s):
  24. * Doug Turner <[email protected]>
  25. * Christopher Blizzard <[email protected]>
  26. * Darin Fisher <[email protected]>
  27. *
  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.
  39. *
  40. * ***** END LICENSE BLOCK ***** */
  41. #include "nsISupports.idl"
  42. interface nsISimpleEnumerator;
  43. /**
  44. * This is the only correct cross-platform way to specify a file.
  45. * Strings are not such a way. If you grew up on windows or unix, you
  46. * may think they are. Welcome to reality.
  47. *
  48. * All methods with string parameters have two forms. The preferred
  49. * form operates on UCS-2 encoded characters strings. An alternate
  50. * form operates on characters strings encoded in the "native" charset.
  51. *
  52. * A string containing characters encoded in the native charset cannot
  53. * be safely passed to javascript via xpconnect. Therefore, the "native
  54. * methods" are not scriptable.
  55. *
  56. * @status FROZEN
  57. */
  58. [scriptable, uuid(c8c0a080-0868-11d3-915f-d9d889d48e3c)]
  59. interface nsIFile : nsISupports
  60. {
  61. /**
  62. * Create Types
  63. *
  64. * NORMAL_FILE_TYPE - A normal file.
  65. * DIRECTORY_TYPE - A directory/folder.
  66. */
  67. const unsigned long NORMAL_FILE_TYPE = 0;
  68. const unsigned long DIRECTORY_TYPE = 1;
  69. /**
  70. * append[Native]
  71. *
  72. * This function is used for constructing a descendent of the
  73. * current nsIFile.
  74. *
  75. * @param node
  76. * A string which is intended to be a child node of the nsIFile.
  77. * For the |appendNative| method, the node must be in the native
  78. * filesystem charset.
  79. */
  80. void append(in AString node);
  81. [noscript] void appendNative(in ACString node);
  82. /**
  83. * Normalize the pathName (e.g. removing .. and . components on Unix).
  84. */
  85. void normalize();
  86. /**
  87. * create
  88. *
  89. * This function will create a new file or directory in the
  90. * file system. Any nodes that have not been created or
  91. * resolved, will be. If the file or directory already
  92. * exists create() will return NS_ERROR_FILE_ALREADY_EXISTS.
  93. *
  94. * @param type
  95. * This specifies the type of file system object
  96. * to be made. The only two types at this time
  97. * are file and directory which are defined above.
  98. * If the type is unrecongnized, we will return an
  99. * error (NS_ERROR_FILE_UNKNOWN_TYPE).
  100. *
  101. * @param permissions
  102. * The unix style octal permissions. This may
  103. * be ignored on systems that do not need to do
  104. * permissions.
  105. */
  106. void create(in unsigned long type, in unsigned long permissions);
  107. /**
  108. * Accessor to the leaf name of the file itself.
  109. * For the |nativeLeafName| method, the nativeLeafName must
  110. * be in the native filesystem charset.
  111. */
  112. attribute AString leafName;
  113. [noscript] attribute ACString nativeLeafName;
  114. /**
  115. * copyTo[Native]
  116. *
  117. * This will copy this file to the specified newParentDir.
  118. * If a newName is specified, the file will be renamed.
  119. * If 'this' is not created we will return an error
  120. * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
  121. *
  122. * copyTo may fail if the file already exists in the destination
  123. * directory.
  124. *
  125. * copyTo will NOT resolve aliases/shortcuts during the copy.
  126. *
  127. * @param newParentDir
  128. * This param is the destination directory. If the
  129. * newParentDir is null, copyTo() will use the parent
  130. * directory of this file. If the newParentDir is not
  131. * empty and is not a directory, an error will be
  132. * returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For the
  133. * |CopyToNative| method, the newName must be in the
  134. * native filesystem charset.
  135. *
  136. * @param newName
  137. * This param allows you to specify a new name for
  138. * the file to be copied. This param may be empty, in
  139. * which case the current leaf name will be used.
  140. */
  141. void copyTo(in nsIFile newParentDir, in AString newName);
  142. [noscript] void CopyToNative(in nsIFile newParentDir, in ACString newName);
  143. /**
  144. * copyToFollowingLinks[Native]
  145. *
  146. * This function is identical to copyTo with the exception that,
  147. * as the name implies, it follows symbolic links. The XP_UNIX
  148. * implementation always follow symbolic links when copying. For
  149. * the |CopyToFollowingLinks| method, the newName must be in the
  150. * native filesystem charset.
  151. */
  152. void copyToFollowingLinks(in nsIFile newParentDir, in AString newName);
  153. [noscript] void copyToFollowingLinksNative(in nsIFile newParentDir, in ACString newName);
  154. /**
  155. * moveTo[Native]
  156. *
  157. * A method to move this file or directory to newParentDir.
  158. * If a newName is specified, the file or directory will be renamed.
  159. * If 'this' is not created we will return an error
  160. * (NS_ERROR_FILE_TARGET_DOES_NOT_EXIST).
  161. * If 'this' is a file, and the destination file already exists, moveTo
  162. * will replace the old file.
  163. *
  164. * moveTo will NOT resolve aliases/shortcuts during the copy.
  165. * moveTo will do the right thing and allow copies across volumes.
  166. * moveTo will return an error (NS_ERROR_FILE_DIR_NOT_EMPTY) if 'this' is
  167. * a directory and the destination directory is not empty.
  168. * moveTo will return an error (NS_ERROR_FILE_ACCESS_DENIED) if 'this' is
  169. * a directory and the destination directory is not writable.
  170. *
  171. * @param newParentDir
  172. * This param is the destination directory. If the
  173. * newParentDir is empty, moveTo() will rename the file
  174. * within its current directory. If the newParentDir is
  175. * not empty and does not name a directory, an error will
  176. * be returned (NS_ERROR_FILE_DESTINATION_NOT_DIR). For
  177. * the |moveToNative| method, the newName must be in the
  178. * native filesystem charset.
  179. *
  180. * @param newName
  181. * This param allows you to specify a new name for
  182. * the file to be moved. This param may be empty, in
  183. * which case the current leaf name will be used.
  184. */
  185. void moveTo(in nsIFile newParentDir, in AString newName);
  186. [noscript] void moveToNative(in nsIFile newParentDir, in ACString newName);
  187. /**
  188. * This will try to delete this file. The 'recursive' flag
  189. * must be PR_TRUE to delete directories which are not empty.
  190. *
  191. * This will not resolve any symlinks.
  192. */
  193. void remove(in boolean recursive);
  194. /**
  195. * Attributes of nsIFile.
  196. */
  197. attribute unsigned long permissions;
  198. attribute unsigned long permissionsOfLink;
  199. /**
  200. * File Times are to be in milliseconds from
  201. * midnight (00:00:00), January 1, 1970 Greenwich Mean
  202. * Time (GMT).
  203. */
  204. attribute PRInt64 lastModifiedTime;
  205. attribute PRInt64 lastModifiedTimeOfLink;
  206. /**
  207. * WARNING! On the Mac, getting/setting the file size with nsIFile
  208. * only deals with the size of the data fork. If you need to
  209. * know the size of the combined data and resource forks use the
  210. * GetFileSizeWithResFork() method defined on nsILocalFileMac.
  211. */
  212. attribute PRInt64 fileSize;
  213. readonly attribute PRInt64 fileSizeOfLink;
  214. /**
  215. * target & path
  216. *
  217. * Accessor to the string path. The native version of these
  218. * strings are not guaranteed to be a usable path to pass to
  219. * NSPR or the C stdlib. There are problems that affect
  220. * platforms on which a path does not fully specify a file
  221. * because two volumes can have the same name (e.g., XP_MAC).
  222. * This is solved by holding "private", native data in the
  223. * nsIFile implementation. This native data is lost when
  224. * you convert to a string.
  225. *
  226. * DO NOT PASS TO USE WITH NSPR OR STDLIB!
  227. *
  228. * target
  229. * Find out what the symlink points at. Will give error
  230. * (NS_ERROR_FILE_INVALID_PATH) if not a symlink.
  231. *
  232. * path
  233. * Find out what the nsIFile points at.
  234. *
  235. * Note that the ACString attributes are returned in the
  236. * native filesystem charset.
  237. *
  238. */
  239. readonly attribute AString target;
  240. [noscript] readonly attribute ACString nativeTarget;
  241. readonly attribute AString path;
  242. [noscript] readonly attribute ACString nativePath;
  243. boolean exists();
  244. boolean isWritable();
  245. boolean isReadable();
  246. boolean isExecutable();
  247. boolean isHidden();
  248. boolean isDirectory();
  249. boolean isFile();
  250. boolean isSymlink();
  251. /**
  252. * Not a regular file, not a directory, not a symlink.
  253. */
  254. boolean isSpecial();
  255. /**
  256. * createUnique
  257. *
  258. * This function will create a new file or directory in the
  259. * file system. Any nodes that have not been created or
  260. * resolved, will be. If this file already exists, we try
  261. * variations on the leaf name "suggestedName" until we find
  262. * one that did not already exist.
  263. *
  264. * If the search for nonexistent files takes too long
  265. * (thousands of the variants already exist), we give up and
  266. * return NS_ERROR_FILE_TOO_BIG.
  267. *
  268. * @param type
  269. * This specifies the type of file system object
  270. * to be made. The only two types at this time
  271. * are file and directory which are defined above.
  272. * If the type is unrecongnized, we will return an
  273. * error (NS_ERROR_FILE_UNKNOWN_TYPE).
  274. *
  275. * @param permissions
  276. * The unix style octal permissions. This may
  277. * be ignored on systems that do not need to do
  278. * permissions.
  279. */
  280. void createUnique(in unsigned long type, in unsigned long permissions);
  281. /**
  282. * clone()
  283. *
  284. * This function will allocate and initialize a nsIFile object to the
  285. * exact location of the |this| nsIFile.
  286. *
  287. * @param file
  288. * A nsIFile which this object will be initialize
  289. * with.
  290. *
  291. */
  292. nsIFile clone();
  293. /**
  294. * Will determine if the inFile equals this.
  295. */
  296. boolean equals(in nsIFile inFile);
  297. /**
  298. * Will determine if inFile is a descendant of this file
  299. * If |recur| is true, look in subdirectories too
  300. */
  301. boolean contains(in nsIFile inFile, in boolean recur);
  302. /**
  303. * Parent will be null when this is at the top of the volume.
  304. */
  305. readonly attribute nsIFile parent;
  306. /**
  307. * Returns an enumeration of the elements in a directory. Each
  308. * element in the enumeration is an nsIFile.
  309. *
  310. * @return NS_ERROR_FILE_NOT_DIRECTORY if the current nsIFile does
  311. * not specify a directory.
  312. */
  313. readonly attribute nsISimpleEnumerator directoryEntries;
  314. };
  315. %{C++
  316. #ifdef MOZILLA_INTERNAL_API
  317. #include "nsDirectoryServiceUtils.h"
  318. #endif
  319. %}