Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dzien 2 #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/data/zadanie01/sum.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
108
29 changes: 28 additions & 1 deletion app/zadanie01.js
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
//Twój kod
const fs = require('fs');

fs.readFile('/home/magdalena/Dokumenty/Coderslab/Dzien2/app/data/zadanie01/input.json', 'utf8', (err, data) => {
if (err==null){
console.log('Poprawnie odczytano plik', data);

var jason= JSON.parse(data);
var sum=0;

jason.forEach(element => {
sum+=parseInt(element);

});
console.log(sum);

fs.writeFile('/home/magdalena/Dokumenty/Coderslab/Dzien2/app/data/zadanie01/sum.txt', sum, err => {
if (err === null) {
console.log('Zapisano poprawnie!');

} else {
console.log('Błąd podczas zapisu pliku', err);
}
});
}

else {
console.log('Błąd podczas odczytu', err); }
});
26 changes: 25 additions & 1 deletion app/zadanie02.js
Original file line number Diff line number Diff line change
@@ -1 +1,25 @@
//Twój kod
const fs = require('fs');
const dir='/home/magdalena/Dokumenty/Coderslab/Dzien2/app/data/zadanie02';

fs.readdir(dir, (err, files) => {

if (err === null) {
console.log('Lista plików:');
files.forEach(file => {
console.log(file);

fs.readFile(dir + '/' + file, 'utf8', (err, data) => {
if (err === null){
console.log('Poprawnie odczytano plik.', data);
} else {
console.log('Błąd podczas odczytu pliku!', err);
}
});


});
} else {
console.log('Błąd podczas listowania katalogu!', err);

}
});