Hi guys! I found there isn't "scandir" in current Guile. And we may use "ftw" to instead. I guess "ftw" traverse all sub-directoies. Yes, we may use nftw to filter the level we don't need, but "ftw" seems always traverse all sub-directories. If my guess is correct, I believe it's too slow for someone, for a instance, me. :-) But the efficiency is not the case. The reason is that when I was trying to write a web server ,I need to print directory content in HTML back to the client. And I found "ftw" won't return "." and "..", moreover ,the result isn't sorted. And I think "scandir" which provided by POSIX is a better solution. Many dynamic language like PHP own a "scandir" implementation. I believe Guile should have one. So I wrote an implementation into filesys.c.
There's a little difference of usage between C and Guile version. But it's trivial if you're familiar with the C version. The usage is like this: ------------------------------- scandir dir [filter [sort]] ------------------------------- "dir" must be a string which owned by a directory. You may run with one arg directly: ------------------ (scandir "mmr") ==>("." ".." "a" "b" "c" "dd" "dir1" "dir2") ------------------ As you see, it returned a list contained all contents of directory "mmr". So, you can do whatever you like with a list. And you may use filter: ------------------------ (scandir "mmr" (lambda (fname) (if (string-contains fname "dir") #f #t))) ==> ("." ".." "a" "b" "c" "dd") ------------------------ It's easy to filter the file you want. Return #f will skip current file, #t will add it to the result list. And the third arg "sort" has only two possibility: 'asort stands for alphasort or 'vsort stands for versionsort Call "scandir" with "sort" unspecified you'll get 'asort in default. If you can't understand that, you may checkout the C version manual: ---------------- man 3 scandir ---------------- Besides, there's a clumsy documentation in the REPL: ------------- ,d scandir ------------- PS: There must be some bugs in this implementation, like portable problem. I believe I didn't add some critical macro in it. But I think there're lots of people know more than me in the mail-list. So I submit it, and waiting for any advices or patches of patch. :-) Anyway, I've tested it. It's function complete. Use it as you like! My patch will be submitted in the next mail, I found some guy(like me) doesn't like to open an attachment of obscure origin. ;-) -- GNU Powered it GPL Protected it GOD Blessed it HFG - NalaGinrut --hacker key-- v4sw7CUSMhw6ln6pr8OSFck4ma9u8MLSOFw3WDXGm7g/l8Li6e7t4TNGSb8AGORTDLMen6g6RASZOGCHPa28s1MIr4p-x hackerkey.com ---end key---