I have the path of a folder in a variable, and for a custom debugging script I am making, i need to find an executable file inside that folder (the executable find is guaranteed to exist, but not to be unique).

The executable file is guaranteed to be inside the folder, not in a subfolder. How can I find the path of an executable file (preferably that when called it always returns the same path, although not necessary) in VimScript?



I don't fully understand your question, i know two ways to find all executable files inside a folder:

readdir( require patch 8.1.1120)

echo readdir('dir', {v-> executable('dir/' . v) && !isdirectory('dir/' .  v)})

:h readdir() return a list of files and subdirectories, you can provide a :h lambda expression to filter it. The return name is not preceded with dir/.


echo filter(glob('dir/*', 0, 1), {i,v-> executable(v) && !isdirectory(v)})

This is how we do it before readdir exists. Third arg of glob make it return a list instead of string. The return name is preceded with dir/.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.