Robust operating system directory functionality
Table of Contents
Install
npm install ack-path
Import
How to import this package
var Path = __dirname console//true test //Now, you can do a whole lot more! Continue reading...
CLI Commands
Timesaver script commands
How to Use
Using the most basic command as an example, you can invoke the copy command, using any of the following methods:
package.json script example
"scripts": "copy": "ack-path copy ./relativeFrom ./relativeTo"
from command terminal example
./node_modules/bin/ack-path copy ./relativeFrom ./relativeTo
Copy
ack-path copy ./relativeFrom ./relativeTo
Move
ack-path move ./relativeFrom ./relativeTo
Delete
ack-path delete ./relativePath
Directory Functionality
.join()
write file promise
Path
.param()
Create directory if not existant. Does not take into condsideration if path is actually a file (file path will be created as a folder)
Path
.paramDir()
Create directory if not existant. Takes condsideration if path is actually a file and only creates folder pathing
Returns promise with context of this Path
Path
.copyTo()
Path
.moveTo()
move entire directory or single file
Path
Path
.rename()
in-place rename directory or single file
Path
Path
.delete()
path delete promise
Path
.each()
file and folder looper
- Based on options, you can recursively read directories and/or files. returns promise
- Runs using npm package readdir. See npm readdir for more usage instructions.
- Arguments
- eachCall function(String:path, Number:index)
- options
- recursive : true
- INCLUDE_DIRECTORIES : true
- INCLUDE_HIDDEN : true
- filter : ['/.js','/.jade']
- excludeByName : name=>yesNo
Path
.eachFilePath()
Loop folder to fire callback for each file found. Only produces file results. see eachPath function
Path
recur
Recursively loop folder to fire callback for each item found. See eachPath function
Path
.recurFiles()
Recursively loop folder to fire callback for each file found. See eachPath function
Path
String Manipulations
var PathTest = '/test/file.js' PathTestpath == "/test/file"PathTestpath == "/test/"
isDirectory
hard-checks file system if item is a folder
'/test/file.js'
isFile
hard-checks file system if item is a file
'/test/file.js'
isLikeFile
Checks string for a file extension
'/test/file.js' == true
getLastName
Returns item after last slash
'/test/file.js' == 'file.js''/test/folder/' == 'folder'
SYNC Examples
.sync().dirExists()
considers if path is actually a file
PathSync
.sync().exists()
PathSync
.sync().delete()
PathSync
.sync().copyTo()
PathSync
.sync().moveTo()
PathSync
File Functionality
A more file specific set of objective functionality
require.file
var File = __dirnamevar filePath = Filepath
.file().copyTo()
File
.file().moveTo()
File
.file().delete()
File
.file().getMimeType()
File//Ex: application/javascript
.file().stat()
File
.file().write()
File
.file().param()
just like write but if file already exists, no error will be thrown
File
.file().append()
File
.file().readJson()
File