Advertisement
Void-voiD

Untitled

Dec 21st, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. #! /usr/bin/env node
  2. 'use-strict'
  3.  
  4. const process = require('process');
  5. const fs = require('fs');
  6. let t = {};
  7. t.wFT = true;
  8.  
  9. try {
  10. const f = (dir, len) => {
  11. const items = fs.readdirSync(dir, t);
  12. for (let i = 0; i < items.length; i++) {
  13. let cur = items[i];
  14. if (cur[0] !== '.') {
  15. let now = cur;
  16. cur = dir + '/' + now;
  17. if (fs.lstatSync(cur).isDirectory()) {
  18. console.log(len + now);
  19. numdir++;
  20. f(cur, len + ' ');
  21. }
  22. else {
  23. console.log(len + now);
  24. numfil++;
  25. }
  26. }
  27. }
  28. }
  29. const g = (dir, len) => {
  30. const items = fs.readdirSync(dir, t);
  31. for (let i = 0; i < items.length; i++) {
  32. let cur = items[i];
  33. if (cur[0] !== '.') {
  34. let now = cur;
  35. cur = dir + '/' + now;
  36. if (fs.lstatSync(cur).isDirectory()) {
  37. console.log(len + now);
  38. numdir++;
  39. g(cur, len + ' ');
  40. }
  41. }
  42. }
  43. }
  44. const h = (dir, len) => {
  45. const items = fs.readdirSync(dir, t);
  46. for (let i = 0; i < items.length; i++) {
  47. let cur = items[i];
  48. if (cur[0] !== '.') {
  49. let now = cur;
  50. cur = dir + '/' + now;
  51. if (fs.lstatSync(cur).isDirectory()) {
  52. fs.appendFileSync('out.txt', len + now + '\n');
  53. numdir++;
  54. h(cur, len + ' ');
  55. }
  56. else {
  57. fs.appendFileSync('out.txt', len + now + '\n');
  58. numfil++;
  59. }
  60. }
  61. }
  62. }
  63. let arg = process.argv[1];
  64. arg = arg.slice(0, arg.length - 5);
  65. numdir = 0;
  66. numfil = 0;
  67. if (process.argv.length === 2) {
  68. f(arg, '');
  69. console.log('Number of directories: ' + numdir);
  70. console.log('Number of files: ' + numfil);
  71. }
  72. if (process.argv.length === 3) {
  73. g(arg, '');
  74. console.log('Number of directories: ' + numdir);
  75. }
  76. if (process.argv.length === 4) {
  77. h(arg, '');
  78. fs.appendFileSync('out.txt', 'Number of directories: ' + numdir + '\n');
  79. fs.appendFileSync('out.txt', 'Number of files: ' + numfil + '\n');
  80. }
  81. } catch (e) {
  82. console.error(e.message);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement