Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env node
- 'use-strict'
- const process = require('process');
- const fs = require('fs');
- let t = {};
- t.wFT = true;
- try {
- const f = (dir, len) => {
- const items = fs.readdirSync(dir, t);
- for (let i = 0; i < items.length; i++) {
- let cur = items[i];
- if (cur[0] !== '.') {
- let now = cur;
- cur = dir + '/' + now;
- if (fs.lstatSync(cur).isDirectory()) {
- console.log(len + now);
- numdir++;
- f(cur, len + ' ');
- }
- else {
- console.log(len + now);
- numfil++;
- }
- }
- }
- }
- const g = (dir, len) => {
- const items = fs.readdirSync(dir, t);
- for (let i = 0; i < items.length; i++) {
- let cur = items[i];
- if (cur[0] !== '.') {
- let now = cur;
- cur = dir + '/' + now;
- if (fs.lstatSync(cur).isDirectory()) {
- console.log(len + now);
- numdir++;
- g(cur, len + ' ');
- }
- }
- }
- }
- const h = (dir, len) => {
- const items = fs.readdirSync(dir, t);
- for (let i = 0; i < items.length; i++) {
- let cur = items[i];
- if (cur[0] !== '.') {
- let now = cur;
- cur = dir + '/' + now;
- if (fs.lstatSync(cur).isDirectory()) {
- fs.appendFileSync('out.txt', len + now + '\n');
- numdir++;
- h(cur, len + ' ');
- }
- else {
- fs.appendFileSync('out.txt', len + now + '\n');
- numfil++;
- }
- }
- }
- }
- let arg = process.argv[1];
- arg = arg.slice(0, arg.length - 5);
- numdir = 0;
- numfil = 0;
- if (process.argv.length === 2) {
- f(arg, '');
- console.log('Number of directories: ' + numdir);
- console.log('Number of files: ' + numfil);
- }
- if (process.argv.length === 3) {
- g(arg, '');
- console.log('Number of directories: ' + numdir);
- }
- if (process.argv.length === 4) {
- h(arg, '');
- fs.appendFileSync('out.txt', 'Number of directories: ' + numdir + '\n');
- fs.appendFileSync('out.txt', 'Number of files: ' + numfil + '\n');
- }
- } catch (e) {
- console.error(e.message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement