Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ddc_vim/deps.ts>fn.readdir

Dark deno-powered completion framework for neovim/Vim
Go to Latest
function fn.readdir
import { fn } from "https://deno.land/x/ddc_vim@v4.0.2/deps.ts";
const { readdir } = fn;

Return a list with file and directory names in {directory}. You can also use glob() if you don't need to do complicated things, such as limiting the number of matches. The list will be sorted (case sensitive), see the {dict} argument below for changing the sort order.

When {expr} is omitted all entries are included. When {expr} is given, it is evaluated to check what to do: If {expr} results in -1 then no further entries will be handled. If {expr} results in 0 then this entry will not be added to the list. If {expr} results in 1 then this entry will be added to the list. The entries "." and ".." are always excluded. Each time {expr} is evaluated v:val is set to the entry name. When {expr} is a function the name is passed as the argument. For example, to get a list of files ending in ".txt":

readdir(dirname, {n -> n =~ '.txt$'})

To skip hidden and backup files:

readdir(dirname, {n -> n !~ '^\.\|\~$'})

The optional {dict} argument allows for further custom values. Currently this is used to specify if and how sorting should be performed. The dict can have the following members:

sort    How to sort the result returned from the system.
        Valid values are:
            "none"      do not sort (fastest method)
            "case"      sort case sensitive (byte value of
                        each character, technically, using
                        strcmp()) (default)
            "icase"     sort case insensitive (technically
                        using strcasecmp())
            "collate"   sort using the collation order
                        of the "POSIX" or "C" `locale`
                        (technically using strcoll())
        Other values are silently ignored.

For example, to get a list of all files in the current directory without sorting the individual entries:

readdir('.', '1', #{sort: 'none'})

If you want to get a directory tree:

function! s:tree(dir)
    return {a:dir : map(readdir(a:dir),
    \ {_, x -> isdirectory(x) ?
    \          {x : s:tree(a:dir .. '/' .. x)} : x})}
endfunction
echo s:tree(".")

Returns an empty List on error.

Can also be used as a method:

GetDirName()->readdir()

Parameters

denops: Denops
directory: unknown
optional
expr: unknown
optional
dict: unknown

Returns

Promise<unknown[]>