pathlength

File path length checker

npm install pathlength
4 downloads in the last month
                __    __      ___                          __    __         
               /\ \__/\ \    /\_ \                        /\ \__/\ \        
 _____     __  \ \ ,_\ \ \___\//\ \      __    ___      __\ \ ,_\ \ \___    
/\ '__`\ /'__`\ \ \ \/\ \  _ `\\ \ \   /'__`\/' _ `\  /'_ `\ \ \/\ \  _ `\  
\ \ \L\ \\ \L\.\_\ \ \_\ \ \ \ \\_\ \_/\  __//\ \/\ \/\ \L\ \ \ \_\ \ \ \ \ 
 \ \ ,__/ \__/.\_\\ \__\\ \_\ \_\\____\ \____\ \_\ \_\ \____ \ \__\\ \_\ \_\
  \ \ \/ \/__/\/_/ \/__/ \/_/\/_//____/\/____/\/_/\/_/\/___L\ \/__/ \/_/\/_/
   \ \_\                                                /\____/             
    \/_/                                                \_/__/              

pathlength is a simple file path length checker for node.js.

Build Status

Install

Install from npm:

$ npm install pathlength

Usage

Usage: pathlength [options] [target]

Options:

  -h, --help                 output usage information
  -V, --version              output the version number
  -d, --debug                output debug messages
  -f, --filter [expression]  filter expression to use
  -n, --no-headers           don't output headers for certain formats
  -o, --output [format]      format for output
  -p, --progressive          output matches as they are found
  -r, --recursive            check directories recursively
  -s, --stop                 don't search unfiltered directories

Examples

Recursively check for all files within a Temp directory with a path longer than 255 characters:

$ pathlength -rf ">255" ~/Temp

Check for paths length longer than that of the target file/directory:

$ pathlength -rf ">@" ~/Temp

Format the result output as a padded table with headers:

$ pathlength -ro table -f ">@" ~/Temp

Output:

Path                             Length Type      
/Users/neocotic/Temp/bar.txt     28     File      
/Users/neocotic/Temp/foo.txt     28     File      
/Users/neocotic/Temp/sub         24     Directory 
/Users/neocotic/Temp/sub/baz.txt 32     File      
/Users/neocotic/Temp/sub/fu.txt  31     File      

Output the results of the search as they are found:

$ pathlength -rpf ">@" ~/Temp

Formats

$ pathlength -o $FORMAT ~/Temp

Simple (default)

Names: simple s

Example:

/Users/neocotic/Temp:20

Comma-separated values

Names: csv c

Example:

"/Users/neocotic/Temp","20","Directory"

JSON

Names: json j

Example:

[
  {
    "path": "/Users/neocotic/Temp",
    "length": 20,
    "type": "Directory"
  }
]

Table

Names: table t

Notes:

  • Includes headers unless the -n|--no-headers option is used
  • Columns are not padding when running in progressive mode

Example:

Path                 Length Type
/Users/neocotic/Temp 20     Directory

XML

Names: xml x

Example:

<?xml version="1.0" encoding="UTF-8" ?>
<results>
  <result path="/Users/neocotic/Temp" length="20" type="Directory" />
</results>

Programmatically

find([options][, callback]) is used primarily:

var pathlength = require('pathlength')

pathlength.find(
    {
        filter:    ['lte', '255']
      , recursive: true
      , target:    '~/Temp'
    }
  , function (err, dataSet) {
      if (err) throw err
      // Process data set...
    }
)

Options

The following options are recognised by this method (all of which are optional);

Property Description
context Context in which to call the callback function
filter Filter expression used to check files/directories
recursive Check directories recursively
stop Don't check children of unfiltered directories
target Target file/directory to check

Events

Get notified whenever a matching file/directory has been found:

var pathlength = require('pathlength')

pathlength.on('data', function (data) {
  // Process data...
})
pathlength.find({
    filter:    'gt @'
  , recursive: true
  , target:    '~/Temp'
})

The following events can be triggered by this method;

Name Called...
start ...after handling all arguments
afterStart ...before the first beforeData event
betweenData ...before all other beforeData events
beforeData ...before all data events (data argument passed to handlers)
data ...when the result has been stored in the data set (data argument passed to handlers)
afterData ...after all data events (data argument passed to handlers)
beforeEnd ...after the last afterData event (dataSet argument passed to handlers)
end ...in parallel with the callback function (dataSet argument passed to handlers)

Properties

pathlength.on('end', function (dataSet) {
  dataSet.forEach(function (data) {
    console.log(data.path)      // e.g. /Users/neocotic/Temp
    console.log(data.length)    // e.g. 20
    console.log(data.directory) // e.g. true
  })
})

Filters

Filters simply consist of a comparison operator followed by an operand.

A wildcard (*) character replaces any invalid filter component(s), which will result in all files and directories being included in the results.

Operators Description
! != ne Not equal to
= == eq Equal to
> gt Greater than
>= gte Greater than or equal to
< lt Less than
<= lte Less than or equal to

Operands can consist of numeric characters or one of the following special characters, which are replaced with their corresponding value:

Character Value
@ Length of the target file/directory

Bugs

If you have any problems with this library or would like to see the changes currently in development you can do so here;

https://github.com/neocotic/pathlength/issues

Questions?

Take a look at docs/pathlength.html to get a better understanding of what the code is doing.

If that doesn't help, feel free to follow me on Twitter, @neocotic.

However, if you want more information or examples of using this library please visit the project's homepage;

http://neocotic.com/pathlength

npm loves you