forked from glrodasz/contentr
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfileOperations.js
More file actions
37 lines (33 loc) · 892 Bytes
/
fileOperations.js
File metadata and controls
37 lines (33 loc) · 892 Bytes
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
import fs from "node:fs/promises";
export async function createFolder(folderName) {
try {
await fs.mkdir(folderName, { recursive: true });
} catch (error) {
console.error("Error creating folder:", error.message);
throw error;
}
}
export async function copyFile(source, destination) {
try {
await fs.copyFile(source, destination);
} catch (error) {
console.error("Error copying file:", error.message);
throw error;
}
}
export async function readFileContent(filePath) {
try {
return await fs.readFile(filePath, "utf-8");
} catch (error) {
console.error("Error reading file:", error.message);
throw error;
}
}
export async function writeOutputFile(filePath, data) {
try {
await fs.writeFile(filePath, JSON.stringify(data));
} catch (error) {
console.error("Error writing output file:", error.message);
throw error;
}
}