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

reading files #9

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 25 additions & 0 deletions mdLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const fs = require('fs');
const chalk = require('chalk');
const path = process.openStdin();
/*
//pediir path y mostarlo
console.log(chalk.cyan("Ingrese path:"));

path.addListener("data", (data) => {

console.log(chalk.magenta("Tu path es: " + data.toString()));
// Require the given module


});*/


//mostar directorio
const items = fs.readdirSync('./test', {withFileTypes: true});

for (let item of items) {
const type = item.isDirectory() ? 'folder' : 'file';
console.log(chalk.blue(`${item.name}: ${type}`));
}

process.exit();
139 changes: 139 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,28 @@
"version": "0.1.0",
"engines": {
"node": ">=16.x"
},
"description": "* [1. Preámbulo](#1-preámbulo)\r * [2. Resumen del proyecto](#2-resumen-del-proyecto)\r * [3. Objetivos de aprendizaje](#3-objetivos-de-aprendizaje)\r * [4. Consideraciones generales](#4-consideraciones-generales)\r * [5. Criterios de aceptación mínimos del proyecto](#5-criterios-de-aceptación-mínimos-del-proyecto)\r * [6. Entregables](#6-entregables)\r * [7. Hacker edition](#7-hacker-edition)\r * [8. Pistas, tips y lecturas complementarias](#8-pistas-tips-y-lecturas-complementarias)\r * [9. Checklist](#9-checklist)\r * [10. Achicando el problema](#10-achicando-el-problema)",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Liz2208/CDMX013-md-links.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Liz2208/CDMX013-md-links/issues"
},
"homepage": "https://github.com/Liz2208/CDMX013-md-links#readme",
"dependencies": {
"chalk": "^4.1.2",
"fs": "^0.0.1-security"
}
}
13 changes: 13 additions & 0 deletions test/mdLinks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const chalk = require('chalk'); //colores
const fs = require('fs').promises;

async function main () {
await findFiles('test');
}

main ();

async function findFiles(folderName) {
const mineFiles = await fs.readdir(folderName);
console.log(mineFiles);
}
Empty file added test/module.js
Empty file.
69 changes: 69 additions & 0 deletions test/notitas.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
console.log(chalk.cyan("Ingrese path:"));

path.addListener("data", (data) => {

console.log(chalk.magenta("Tu path es: " + data.toString()));
// Require the given module

process.exit();

//prueba dos
const path = process.openStdin();

console.log(chalk.blue("Ingrese path:"));


path.addListener("data", (data) => {
const file = data.toString();
console.log(chalk.yellow("Tu path es: " + file));
fs.readFile(file, 'utf-8', (err, data) => {
if(err){
console.log(chalk.red('error no se encuentra archivo', err));
}else {
console.log(chalk.magenta(data,toString));

}
process.exit();
})


//console.log(items);

const items = fs.readdir('stores', {withFileTypes: true});
for (let item of items) {
const type = item.isDirectory() ? 'folder' : 'file';
console.log(`${item.name}: ${type}`);
}

function findFiles(folderName) {
const items = fs.readdir(folderName, {withFileTypes: true});
items.forEach((item) => {
if (path.extname(item.name) === 'md'){
console.log(chalk.magenta(`Found file: ${item.name} in folder: ${folderName}`));
}
else {
findFiles(path.join(folderName, item.name));
}
});
}
findFiles('stores');


})

//3er prueba
var texto = fs.readFileSync('notitas.txt', {encoding:'utf-8'});
console.log(chalk.blue(texto));


//prueba video
async function main () {
await findFiles('test');
}

main ();

async function findFiles(folderName) {
const mineFiles = await fs.readdir(folderName);
console.log(mineFiles);
}