-
Notifications
You must be signed in to change notification settings - Fork 0
/
files.js
executable file
·101 lines (56 loc) · 1.6 KB
/
files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
var fs = require('fs')
/**
* sync code
* */
// var fileContent = fs.readFileSync('readme.txt','UTF-8')
// console.log(fileContent)
// fs.writeFileSync('writeMe.txt',fileContent)
/***
* non-sync code
*/
// fs.readFile('readme.txt','UTF-8',function(error,data) {
// console.log('data is '+ data)
// fs.writeFile('writeme2.txt',data,function(error) {
// if(error != null) {
// console.log('error writing file' + error)
// }
// })
// });
// console.log('is this blocking. ? ')
// fs.writeFileSync('writeMe.txt',fileContent)
/****
* Delete the file
*/
// fs.unlinkSync('writeme2.txt')
/****
* make a directory
*/
// fs.mkdirSync('stuff-dir')
/****
* remove a directory
*/
// fs.rmdirSync('stuff-dir')
// fs.mkdir('stuff-dir',function(){
// console.log('directory created successfully')
// fs.readFile('readme.txt','utf8',function(err,data) {
// console.log("content of file "+data)
// fs.writeFile('./stuff-dir/stufffile.txt',data, function(err) {
// if(err !=null) {
// console.error('Exception writing to file')
// }
// })
// })
// })
// remove directory - can be removed only if directory is empty
// fs.unlink('./stuff-dir/stufffile.txt',function(err){
// if(err !=null ) {
// console.error('error removing file ')
// return
// }
// fs.rmdir('./stuff-dir',function(err){
// if(err !=null ) {
// console.error('error removing directory ')
// return
// }
// })
// })