forked from aniani/vim
patch 8.1.1120: cannot easily get directory entry matches
Problem: Cannot easily get directory entry matches. Solution: Add the readdir() function. (Yasuhiro Matsumoto, closes #2439)
This commit is contained in:
@@ -2507,6 +2507,9 @@ py3eval({expr}) any evaluate |python3| expression
|
||||
pyxeval({expr}) any evaluate |python_x| expression
|
||||
range({expr} [, {max} [, {stride}]])
|
||||
List items from {expr} to {max}
|
||||
readdir({directory} [, {expr}])
|
||||
List file names on {dir} with evalating
|
||||
{expr}
|
||||
readfile({fname} [, {type} [, {max}]])
|
||||
List get list of lines from file {fname}
|
||||
reg_executing() String get the executing register name
|
||||
@@ -7255,6 +7258,33 @@ range({expr} [, {max} [, {stride}]]) *range()*
|
||||
range(2, -2, -1) " [2, 1, 0, -1, -2]
|
||||
range(0) " []
|
||||
range(2, 0) " error!
|
||||
<
|
||||
*readdir()*
|
||||
readdir({directory} [, {expr}])
|
||||
Return a list with file and directory names in {directory}.
|
||||
|
||||
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.
|
||||
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 !~ '^\.\|\~$'})
|
||||
|
||||
< 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(".")
|
||||
<
|
||||
*readfile()*
|
||||
readfile({fname} [, {type} [, {max}]])
|
||||
|
||||
Reference in New Issue
Block a user