diff runtime/doc/eval.txt @ 16231:0761a4c111a7 v8.1.1120

patch 8.1.1120: cannot easily get directory entry matches commit https://github.com/vim/vim/commit/543c9b1921d7605498b54afdef518e312f1b4515 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Apr 5 22:50:40 2019 +0200 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 https://github.com/vim/vim/issues/2439)
author Bram Moolenaar <Bram@vim.org>
date Fri, 05 Apr 2019 23:00:06 +0200
parents abb67309c1ca
children 219c58b3879c
line wrap: on
line diff
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2507,6 +2507,9 @@ py3eval({expr})			any	evaluate |python3|
 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
@@ -7256,6 +7259,33 @@ range({expr} [, {max} [, {stride}]])				
 			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}]])
 		Read file {fname} and return a |List|, each line of the file