-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnode.mjs
More file actions
59 lines (53 loc) · 1.49 KB
/
node.mjs
File metadata and controls
59 lines (53 loc) · 1.49 KB
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
import fs from 'node:fs/promises'
/* try{
await fs.access('./content/file.txt',fs.constants.R_OK | fs.constants.W_OK)
console.log('can access')
}catch(error){
console.log(`can't access ${error}`)
}
try {
await fs.appendFile('./content/file.txt','New Log Entry')
console.log('log updated')
} catch (error) {
console.log(`cannot append ${error}`)
}
try {
await fs.copyFile('./content/file.txt','./file-system/copt.txt',fs.constants.COPYFILE_EXCL)
console.log('successfull copy');
} catch (error) {
console.log(`unable to copy ${error}`);
}
try {
// for await(const entry of fs.glob("***.txt",{nodir:true})){
console.log(entry)
}
} catch (error) {
console.log(`unableto get files ${error}`);}
try {
await fs.link('./content/subfolder/boom.txt','fun.txt')
if (fs.readFile('fun.txt')){
console.log('success acessing')
}
if(fs.unlink('fun.txt'))
{
console.log('removed successfull')
}else{
console.log('removed failed')
}
} catch (error) {
console.log(`unable to link ${error}`);
}*/
try {
const dir=await fs.readdir('./content',{withFileTypes:true})
for await(const dirent of dir){
console.log(dirent.name,dirent.isDirectory())
}
} catch (error) {
console.log(`unable to get dir ${error}`);
}
try {
const food=fs.readFile('./package.json','utf8')
console.log(await food)
} catch (error) {
console.log(`unable to read ${error}`)
}