Of course I can just do
let dir = globpath('path', '*', 0, 1)
for file in dir
if (isdirectory(file))
add(myDirList, file)
endif
endfor
But this will have to go through all the files in the directory and when the list is large this can take quite a long time. Is there a more efficient way of doing this?
Edit: Response to @Luc Hermitte
Testing globpath()
and for
loop together: 66.73 seconds.
Testing globpath()
and filter
together: 64.11 seconds.
A couple things to note about my specific situation.
- I'm trying to access a network drive.
- My first tests where done on wifi. I've connected with a hard wire and times have been reduced by about 25%.
- The directory I'm accessing has ~2500 files/directories on it.
I've now tested the individual times on a hard wire connection and got the following times:
globpath()
: 40.19 secondsfor
loop: 4.96 secondsfilter
: 4.91 secondssystem('dir "path"')
: 0.17 seconds... (I'm on Windows obviously)
Not sure why for
and filter
are so close when I got better results with filter
before...
So yeah, the external is magnitudes faster. You think this deserves a bug report?
P.S. I used globpath()
because I didn't want to cd
to the directory, but now I know that's not necessary.
find
) an option?