Prev | Current Page 586 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

Thankfully, Neko provides a handy readDirectory function for
listing the contents of a directory as an array of strings:
var contents : Array < String > = neko.FileSystem.readDirectory( ???../images??? );
Once you have your string array, you need to work out whether each item is a directory or a file. This
can be done in one of two ways. First, you can use the isDirectory method. This method expects a
string representing the path to the file or directory you want to query and will return a Boolean value;
true if the path is a directory and false if it isn ??™ t. If the path leads to a file or directory that does not
exist, then an exception will be thrown.
304
Part II: Server Side, JavaScript, and Flash: Oh My!
The second option is to use the kind method. This method will return kdir of the neko.FileKind
enumerator if the path is a directory, kfile if it ??™ s a file, or will throw an exception if the path does not
exist. A third enumerator, kother , may also be provided should the specified path be neither a file nor a
directory.


Pages:
574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598