disk-action
Easy to use module in order to create / delete / modify files and directory. All unexistent directories will be create 'on-the-fly', and delete works for either file or directory. ** BE CAREFUL ** when specifying directory: all content will be erased !!
Important: This package is NOT backward compatible with 0.1.x versions... Be careful if you update your npm project...
Install
Install with npm:
npm install disk-action
Basic Usage
Require the module:
Disk = require 'disk-action'
Initialize with encoding (default is 'utf-8'):
disk = 'utf-8'
Read a file:
diskread filename: 'directory/not/created/hello.txt' : consolelog data
Methods available:
- read() read a file
- touch() create empty file
- write() similar to create() for backward compatibility
- create() create a file or directory
- append() append content to a file
- copy() copy a file/directory
- move() move a file directory
- replace() replace string in file
- delete() delete file/directory
Methods usage:
Read a file:
diskread filename: 'directory/not/created/hello.txt' : consolelog data
Create file:
diskcreate filename: 'directory/not/created/hello.txt' content: 'I like coffee' : consolelog 'File created'
Create file with content:
diskcreate filename: 'directory/not/created/hello.txt' content: 'I like coffee'
Create directory:
diskcreate dirname: 'another/directory'
Append to file:
diskappend filename: 'directory/not/created/hello.txt' content: 'But JS is not my best friend... ;)'
Copy files:
diskcopy source: 'directory/not/created/hello.txt' destination: 'another/directory/hello2.txt'
Move files:
diskmove source: 'directory/not/created/hello.txt' destination: 'another/directory/hello2.txt'
Replace content in file:
diskreplace filename: 'directory/not/created/hello.txt' to_replace: 'coffee' replace_with: 'CoffeeScript'
Delete file or directory:
diskdelete filename: 'directory/not/created/hello.txt'
Extended usage
All methods supports an optional callback parameter:
diskwrite filename: 'directory/not/created/hello.txt' content: 'I like coffee' cb: do_something
or:
diskread filename: 'directory/not/created/hello.txt' : consolelog data
Run tests
You can run unit-tests using mocha with:
npm test