-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnd9.js
98 lines (89 loc) · 2.44 KB
/
nd9.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
89
90
91
92
93
94
95
96
97
98
const readline = require("readline");
const fs = require("fs");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function skaiciausIvedimas(msg) {
return new Promise((resolve, reject) => {
rl.question(msg, data => {
resolve(parseInt(data));
});
});
}
async function tekstoIvedimas(msg) {
return new Promise((resolve, reject) => {
rl.question(msg, data => {
resolve(data);
});
});
}
function readFile(name, options) {
return new Promise((resolve, reject) => {
fs.readFile(name, options, (err, data) => {
if (err) {
reject(err);
return;
}
resolve(data);
});
});
}
async function main() {
let tekstas = await tekstoIvedimas("Ivesk failo varda a.txt/b.txt/c.txt:");
if (tekstas == "a.txt") {
fs.readFile("a.txt", {
encoding: "utf-8"
}, function (err, data) {
if (err) {
console.log("klaida");
console.log(err);
return;
}
console.log("perskaiciau faila a.txt");
console.log(data);
});
rl.close();
}
if (tekstas == "b.txt") {
fs.readFile("b.txt", {
encoding: "utf-8"
}, function (err, data) {
if (err) {
console.log("klaida");
console.log(err);
return;
}
console.log("perskaiciau faila b.txt");
console.log(data);
});
rl.close();
}
if (tekstas == "c.txt") {
fs.readFile("c.txt", {
encoding: "utf-8"
}, function (err, data) {
if (err) {
console.log("klaida");
console.log(err);
return;
}
console.log("perskaiciau faila c.txt");
console.log(data);
});
rl.close();
}
} main();
/*
1.paprasyti ivesti failo varda
2.perskaityti faila
3.jei perskaite be klaidu - atspausdinti teksta
jei klaidos - atspausdinti klaida
paprasyti ivesti failo vardus (atskirtus tarpais)
pvz: Ivesk failu fardus: a.txt b.txt d.txt
suskaldot stringa per tarpa - gaunat masyva su failu pavadinimais
perskaitot visus failus nurodyta tvarka
jei perskaite be klaidu - kaupti teksta kintamajame
jei klaidos - atspausdinti klaida
pabaigoj atspausdinti sukaupta teksta
*/