There is a built-in glob()
function. To get a list of files in current directory on windows you could use split(glob('.\\*'), "\n")
. On *nix it is much more complicated as
- POSIX allows everything except NULL to be in filename. Everything here means that newline ("\n") is also allowed.
glob()
function does not return filenames starting with dot unless explicitely requested (using glob('dir/.*')
).
- When explicitely requested to list filenames starting with dot
glob()
also shows .
(current directory) and ..
(parent directory) special directories.
In order to solve this problems you have to use something like this (or use vim with python support and python's own os.listdir
function).
If you don't mind having frawor in dependencies, you could do the following:
execute frawor#Setup('0.0', {'@/os': '0.0'})
<...>
let dir_contents=s:_r.os.listdir('.')
About getting list of lines from a shell command: if you know that command you launch won't output NULLs, you can use split(system(cmd), "\n", 1)
(maybe without last argument if you don't care about empty lines). If you know that command may output NULLs and you want to keep them, you have to do more work:
noautocmd new
read !cmd
let s:shell_output=getline(2, line('$'))
noautocmd bwipeout!
Note that NULLs in this case will get replaced with newlines inside a s:shell_output
list, while actual newlines will be represented as string ends.