I'd like to loop over the files in a directory using Vimscript. Reading usr_41.txt
and having searched around, the best I can come up with is something like let dir_contents = system('ls')
But since system()
isn't returning a list, I can't loop over it. Is there either a way I can save the results of a system call as a list, or a Vim command or function that does so already?
You can get a list with split(system('ls'), '\n')
, which will give you a list of files providing you don't have files with newlines in them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With