On Thursday 28 July 2005 21:28, Sergey Plis wrote:
> Hi,
>
> How can I read a list of files from a given directory into an array.
> I want something like
>
> s" /tmp/*txt" read-files -> addr
>
> where addr is start address in memory of a structure whose first
> element is the number of files then length of the first element and
> the string and so on.
>
> It does not have to be exactly like that but should work somehow. For
> now I can just think of generating forth code in bash and then
> including it. But I do not like this idea.

We have (in the DOS vocabulary)

open-dir ( addr u -- wdirid wior )  opens the directory specified by 
addr u, returning a directory id, and an error number to THROW

close-dir ( wdirid -- wior ) closes the directory

read-dir ( addr u1 wdirid -- u2 flag wior ) reads a directory entry into 
the buffer addr u1, and returns the length u2 (=u1 when it doesn't 
fit), a flag if there's nothing more to read, and an error.

filename-match ( addr1 u1 addr2 u2 -- flag ) returns true when the 
pattern addr2 u2 matches the file addr1 u1.

For the file size and things like that, you can use the Unix stat (lstat 
for links), or open-file and file-size.

-- 
Bernd Paysan
"If you want it done right, you have to do it yourself"
http://www.jwdt.com/~paysan/

Attachment: pgp0HlykQYFda.pgp
Description: PGP signature

Reply via email to