JavaScript library for querying file path lengths
pathlength is a simple file path length checker for node.js.
Install from npm:
$ npm install pathlength
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
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
$ pathlength -o $FORMAT ~/Temp
Names:
simple s
Example:
/Users/neocotic/Temp:20
Names:
csv c
Example:
"/Users/neocotic/Temp","20","Directory"
Names:
json j
Example:
[
{
"path": "/Users/neocotic/Temp",
"length": 20,
"type": "Directory"
}
]
Names:
table t
Example:
Path Length Type /Users/neocotic/Temp 20 Directory
Names:
xml x
Example:
<?xml version="1.0" encoding="UTF-8"?>
<results>
<result path="/Users/neocotic/Temp" length="20" type="Directory"/>
</results>
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...
}
)
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 |
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) |
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 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 |
If you have any problems with this library or would like to see the changes currently in development browse our issues.
Take a look at the documentation to get a better understanding of what the code is doing.
If that doesn't help, feel free to follow me on Twitter, @neocotic.