-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.js
58 lines (44 loc) · 1.09 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
const fs = require('fs');
// reading files
// fs.readFile('./docs/blog1.txt', (err,data) => {
// if(err){
// console.log(err);
// }
// console.log(data);
// console.log(data.toString());
// });
// // the program executed before call back function
// console.log('last line');
// writing files
// fs.writeFile('./docs/blog1.txt','hello world',() =>{
// console.log('file was written');
// })
// if file doesn`t exist it makes new file
// fs.writeFile('./docs/blog2.txt','hello world',() =>{
// console.log('file was written');
// })
// directories
// if(!fs.existsSync('./assets')){
// fs.mkdir('./assets', (err) => {
// if(err){
// console.log(err);
// }
// console.log('folder created');
// });
// }else{
// fs.rmdir('./assets',(err)=>{
// if(err){
// console.log(err);
// }
// console.log('folder deleted');
// });
// }
// deleting files
if(fs.existsSync('./docs/deleteme.txt')){
fs.unlink('./docs/deleteme.txt',(err)=>{
if(err){
console.log(err);
}
console.log('file deleted');
});
}