File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ import fs from "node:fs" ;
2+ import process from "node:process" ;
3+
4+ // This will give an array without the path to node and to the file.
5+ const argv = process . argv . slice ( 2 ) ;
6+
7+ // filter the flag to find the target folder.
8+ const filePaths = argv . filter ( ( arg ) => ! arg . startsWith ( "-" ) ) ;
9+ const showHiddenFiles = argv . includes ( "-a" ) ;
10+
11+ // if no folder provide we use the current one
12+ const target = filePaths [ 0 ] || "." ;
13+ // read the file.
14+ const files = fs . readdirSync ( target ) ;
15+
16+ // save the result into the variable.
17+ let filteredFIles = files ;
18+ if ( ! showHiddenFiles ) {
19+ filteredFIles = files . filter ( ( file ) => ! file . startsWith ( "." ) ) ;
20+ } else {
21+ // we use spread operator to merge the paths.
22+ filteredFIles = [ "." , ".." , ...files ] ;
23+ }
24+
25+ // Print using -1 .
26+ filteredFIles . forEach ( ( file ) => {
27+ console . log ( file ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments