[haXe] what is the use of FileKind, FileSystem.kind( path )
Michel Oster
micheloster1 at free.fr
Mon Sep 29 21:08:48 CEST 2008
Juan Delgado wrote :
> About searching for files in the hard disk, I have no idea but I'm
> interested too!
Hi,
your question woke me up. ;-)
import neko.FileSystem;
var ext = 'png';
getFiles( ext );
function getFiles(ext: String): Array<String> {
//note : to use this function, Neko must previously set the
working folder ( setCwd( path.dir ) )
ext = '.' + ext;
var end = ext.length;
var aFileNames = neko.FileSystem.readDirectory( path.dir );
var i = 0;
while( i < aFileNames.length ) {
var out = true;
var fileName = aFileNames[i];
if( FileSystem.kind( fileName ) == neko.FileKind.kfile ) {
//<- if it is a file
var len = fileName.length - end;
//only files with minimum 1 character length AND having
the extension '.ext' :
if( len > 0 && len == fileName.lastIndexOf( ext ) ) out
= false;
}
if( out ) aFileNames.remove( fileName );
else i++;
}
return aFileNames;
}
Michel
More information about the Haxe
mailing list