repl.txt (2575B)
1 2 {{alias}}( oldPath, newPath, clbk ) 3 Asynchronously renames a file. 4 5 The old path can specify a directory. In this case, the new path must either 6 not exist, or it must specify an empty directory. 7 8 The old pathname should not name an ancestor directory of the new pathname. 9 10 If the old path points to the pathname of a file that is not a directory, 11 the new path should not point to the pathname of a directory. 12 13 Write access permission is required for both the directory containing the 14 old path and the directory containing the new path. 15 16 If the link named by the new path exists, the new path is removed and the 17 old path is renamed to the new path. The link named by the new path will 18 remain visible to other threads throughout the renaming operation and refer 19 to either the file referred to by the new path or to the file referred to by 20 the old path before the operation began. 21 22 If the old path and the new path resolve to either the same existing 23 directory entry or to different directory entries for the same existing 24 file, no action is taken, and no error is returned. 25 26 If the old path points to a pathname of a symbolic link, the symbolic link 27 is renamed. If the new path points to a pathname of a symbolic link, the 28 symbolic link is removed. 29 30 If a link named by the new path exists and the file's link count becomes 0 31 when it is removed and no process has the file open, the space occupied by 32 the file is freed and the file is no longer accessible. If one or more 33 processes have the file open when the last link is removed, the link is 34 removed before the function returns, but the removal of file contents is 35 postponed until all references to the file are closed. 36 37 Parameters 38 ---------- 39 oldPath: string|Buffer 40 Old path. 41 42 newPath: string|Buffer 43 New path. 44 45 clbk: Function 46 Callback to invoke upon renaming a file. 47 48 Examples 49 -------- 50 > function done( error ) { 51 ... if ( error ) { 52 ... console.error( error.message ); 53 ... } 54 ... }; 55 > {{alias}}( './beep/boop.txt', './beep/foo.txt', done ); 56 57 58 {{alias}}.sync( oldPath, newPath ) 59 Synchronously renames a file. 60 61 Parameters 62 ---------- 63 oldPath: string|Buffer 64 Old path. 65 66 newPath: string|Buffer 67 New path. 68 69 Returns 70 ------- 71 err: Error|null 72 Error object or null. 73 74 Examples 75 -------- 76 > var err = {{alias}}.sync( './beep/boop.txt', './beep/foo.txt' ); 77 78 See Also 79 -------- 80