This module is meant to handle usage of folders with simple functions.
npm i adirr
let root = "a valid root";
let cm = require("adirr").adirr(root);
there is an option to call adirr(root,true) which will console.log details like where an operation is taking place
- description: simple wrap of the readdirSync.
- params:
notype(string)
: if (notype = "names") return string of names - return: Names of files and directories in the root
- return type: Array of Dirnet || Array of strings
- example:
cm(root).dir()
- description: open folder in the root folder || opens absolute path
- params:
str(string)
- name of the folder to open - return: new handler with updated root
- return type:
adirr
- example:
cm.open(cm(root).dir("names")[1]).dir() //opens the second folder in the root folder and returns its content
- description: make a directory with the given @param@name
- params:
name(string)
- name of the directory to open,openNewDir(bool/string)
- if set totrue
(or "open") open the new dir - return: handler to the root/ to the new directory
- return type:
adirr
- example:
cm.mkdir("newdir","open").mkdir("anothernewdir").dir() // create "newdir/anothernewdir",display newdir
- description: make directories with each name of names array
- params:
names(array)
- contain names of the directories - return: same as above
- return type: same as above
- description: [recursive]search for a file name (regex search) in a folders and all of its sub-folders
- params:
str(string)
- a string to search by a regexsearch - return: returns an object called:
searchedObject {
path: current path
members: [files matched to the search -OR- searchedObject for sub-folders]
}
- return type: object
- example:
cm.search('test.txt')
- description: save the
data
in a (possibly new) file withfname
name in the root folder - params:
fname
- name with extension of the file,(string)data
- the data to append - return: -void-
- example:
cm.save("search-results.txt";,JSON.stringify(cm.search('test.txt'),null,1));
- description: gives an array of all the files (include double names) in that path and all sub directories, makes it very easy to handle and search in massive folder
- params:
str
path that's default is root and can be absolute path - return:
Array
- example: the following function will print only txt files, in the order of the shortest name first.
console.log(cm.files().filter(ele=>{
return path.extname(ele)==".txt";
}).sort((a,b)=> a.length>b.length));
- description: simmple wrapper to readFileSync
- params:
name
- the name of the file, relative to the rootoptions
- an object that my contain optional flag and encoding (default to utf8) - return:
String
||Buffer
- example:
data = cm.read('mytextfile.txt');