How to get directory list from script ?

2 views
Skip to first unread message

Marczis, Peter (NSN - HU/Budapest)

unread,
Nov 24, 2009, 8:52:53 AM11/24/09
to v...@vim.org

Hi,
I would like to write a vim script which reads into a list, the directory tree…
how it is possible to get the subdirectories into a list ? (from PWD for example.)
Thanks a lot in advice.

Br,
        Peter G. Marczis


Tim Chase

unread,
Nov 24, 2009, 1:09:33 PM11/24/09
to vim...@googlegroups.com
>> I would like to write a vim script which reads into a list, the
>> directory tree...
>> how it is possible to get the subdirectories into a list ? (from PWD
>> for example.)

You can read in the output of a shell command, so you can use

:r !find .

on most *nix-like OSes, or on Windows, you can do any of the
following

:r !dir /s/b
:r !dir /s/b/a "include hid/sys files
:r !tree "just subdirs
:r !tree /f "include files
:r !tree /f /a "files and ascii-tree representation

It's OS-specific, so you'd have to read up on your variant. The
"find" command is super-powerful in tuning the files returned (be
sure to read up at the man-pages), whereas the "dir"/"tree"
commands are a bit wanting in flexibility of output.

-tim


Isaac

unread,
Nov 24, 2009, 6:54:34 PM11/24/09
to vim...@googlegroups.com, 善用佳软, n0zai...@googlegroups.com
Thanks! Tim 

I believe this tip is also useful for me and my friends.


--
Regards, Isaac. (李霆钧)
> http://delicious.com/litingjun
> http://litingjun.amplify.com

Luc Hermitte

unread,
Nov 25, 2009, 4:37:05 AM11/25/09
to vim use
Hello,

"Peter Marczis (NSN - HU/Budapest)" <peter....@nsn.com> wrote :
> I would like to write a vim script which reads into a list , the


> directory tree…
> how it is possible to get the subdirectories into a list ? (from PWD
> for example.)

You can also play with:
echo filter(split(globpath(getcwd(), '**'), '\n'), 'isdirectory(v:val)')

It may not be the most efficient way, but it should do the trick.

--
Luc Hermitte
http://lh-vim.googlecode.com/
http://hermitte.free.fr/vim/

Marczis, Peter (NSN - HU/Budapest)

unread,
Nov 25, 2009, 5:06:11 AM11/25/09
to vim...@googlegroups.com
Hi,
thanks for the answers ! This way (see below) is the best for me.

Br,
Peter.

-----Original Message-----
From: vim...@googlegroups.com [mailto:vim...@googlegroups.com] On
Behalf Of ext Luc Hermitte
Sent: Wednesday, November 25, 2009 11:37 AM
To: vim use
Subject: Re: How to get directory list from script ?


Hello,

"Peter Marczis (NSN - HU/Budapest)" <peter....@nsn.com> wrote :
> I would like to write a vim script which reads into a list , the
> directory tree...

Marczis, Peter (NSN - HU/Budapest)

unread,
Nov 25, 2009, 5:28:39 AM11/25/09
to vim...@googlegroups.com
Hi,
what should be the good syntax in this case ?

for item in sacks
menu ]environments.{item} echo "coool"
endfor

sacks is a list. and I would like to create a menu from this list...
but, how can I use the item variable to create the menu ?

thanks for all your trouble !

Br,
Peter.

Marczis, Peter (NSN - HU/Budapest)

unread,
Nov 25, 2009, 6:16:23 AM11/25/09
to vim...@googlegroups.com
Sorry,
by the time I found the answare for myself...

for v in vers
let command = 'menu ]environments.' .
substitute(strpart(v,3), '\', '.', "g") . ' :let $sack="' .
substitute(strpart(v,3), '\', ' ', "g") . '"<CR>'
exec command
endfor

I hope it will help to someone too...

Br,
Peter.

-----Original Message-----
From: vim...@googlegroups.com [mailto:vim...@googlegroups.com] On

Maxim Kim

unread,
Nov 25, 2009, 6:21:29 AM11/25/09
to vim_use


On 25 ноя, 13:28, "Marczis, Peter (NSN - HU/Budapest)"
<peter.marc...@nsn.com> wrote:
> Hi,
> what should be the good syntax in this case ?
>
>             for item in sacks
>                 menu ]environments.{item} echo "coool"
>             endfor
>
> sacks is a list. and I would like to create a menu from this list...
> but, how can I use the item variable to create the menu ?

let items = ['hello', 'vim', 'world']
for item in items
exe 'menu environments.'.item.' :echo "'.item.'"<CR>'
endfor

to get help on 'exe':
:h :execute
Reply all
Reply to author
Forward
0 new messages