README.md (2017B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # chdir 22 23 > Change the current working directory. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var chdir = require( '@stdlib/process/chdir' ); 31 ``` 32 33 #### chdir( path ) 34 35 Changes the current working directory to the specified `path`. 36 37 <!-- run-disable --> 38 39 ```javascript 40 var err = chdir( '/foo/bar' ); 41 ``` 42 43 If the function encounters an error when attempting to change the working directory, the function returns an `error`; otherwise, the function returns `null`. 44 45 </section> 46 47 <!-- /.usage --> 48 49 <section class="notes"> 50 51 ## Notes 52 53 - See [chdir(2)][chdir]. 54 55 </section> 56 57 <!-- /.notes --> 58 59 <section class="examples"> 60 61 ## Examples 62 63 <!-- eslint no-undef: "error" --> 64 65 ```javascript 66 var cwd = require( '@stdlib/process/cwd' ); 67 var chdir = require( '@stdlib/process/chdir' ); 68 69 // Print the current working directory: 70 var dir = cwd(); 71 console.log( dir ); 72 73 // Change the current working directory to the directory of this file: 74 var err = chdir( __dirname ); 75 if ( err ) { 76 console.error( err.message ); 77 } 78 79 // Print the current working directory: 80 console.log( cwd() ); 81 82 // Change the current working directory back to the original directory: 83 err = chdir( dir ); 84 if ( err ) { 85 console.error( err.message ); 86 } 87 88 // Print the current working directory: 89 console.log( cwd() ); 90 ``` 91 92 </section> 93 94 <!-- /.examples --> 95 96 <section class="links"> 97 98 [chdir]: http://man7.org/linux/man-pages/man2/chdir.2.html 99 100 </section> 101 102 <!-- /.links -->