Remove Files

Path: /src/method/remove.coffee compiled to /lib/method/remove.js

This method will remove the given path entry and if it is a directory it will also remove any containing data or only the selection of files.

The option maxdepth is only supported in the search, but if a directory is matched everything within will be deleted.

This method will remove the given path entry and if it is a directory it will also remove any containing data. If some filter given you can also delete# selectively.

To select which files to remove the following options may be used:

  • filter - Array<Object>|ObjectFilter Rules
  • dereference - Boolean dereference symbolic links and go into them
  • ìgnoreErrors - Boolean go on and ignore IO errors
  • parallel - Integer number of maximum parallel calls in asynchronous run (defaults to half of open files limit per process on the system)

Example:

CoffeeScript Code
fs = require 'alinex-fs' fs.remove '/tmp/some/directory', (err, removed) -> return console.error err if err if removed console.log "Directory '"+removed+"' was removed with all it's contents." console.log "Directory no longer exists!"

remove()

Usage:remove(source, options, cb)

Parameter
  • source - String directory or file to be deleted
  • options - Object optional specifications for check defining which files to remove
  • cb - function(Error, Array<String>) optional callback which is called after done with possible Èrror or with the files/directories been deleted

removeSync()

Usage:removeSync(path, options)

Parameter
  • path - String directory or file to be deleted
  • options - Object optional specifications for check defining which files to remove
Return
Array<String> the files or directories been deleted
Throws
  • Error if domething went wrong

Debugging

This module uses thedebug module so you may anytime call your app with the environment setting DEBUG=fs:remove for the output of this method only.

Because there are mkdirs subcalls here you see the output of DEBUG=fs:* while removeing a small directory:

fs:remove check test/temp/dir1 +29ms
fs:filter skip test/temp/dir1 because not in specified depth +1ms
fs:remove going deeper into test/temp/dir1 directory +0ms
fs:remove check test/temp/dir1/file11 +0ms
fs:remove removing test/temp/dir1/file11 (file) +0ms