How to use tango's FileScan correctly?

qwesx qwesx at qwesx.com
Thu Oct 14 08:31:47 PDT 2010


Hello!

I'm trying out some things in D (with tango) and tried to build a *very* 
primitive indexing program. One function requires to run through a 
directory (without recursion) and get me all the files/folders in there.

So after reading the documentation I found that tango.io.FileScan 
basically does what I need. It's just that I can't get it to work. All 
examples there use some filter, but I don't need one. And the other stuff 
I tried (and which compiled) gives me either a wrong number of files in 
my debug output, or none at all.

Here's (part of) my code:

FileScan scan = new FileScan();
// only one of those was used at a time, the others are commented
// dir is a char[] with an existing (absolute) directory:
scan(dir, "*");
scan(dir, ".*");
scan(dir, "*.*");
scan(dir, "");
scan = scan.sweep(dir, false);


FilePath[] myFolders = scan.folders();
FilePath[] myFiles = scan.files();
char[][] err = scan.errors();
Stdout("found folders: ")(myFolders.length)("\n")();
Stdout("found files  : ")(myFiles.length)("\n")();
Stdout("errors:\n")();
foreach (char[] e; err)
  Stdout(e)("\n")();


The result was always:

found folders: 0
found files  : 0
errors:
% _

I think I'm doing something very wrong here. And it's possibly because I 
don't understand the documentation.

Can you help me get this to work?



Regards
qwesx


More information about the Digitalmars-d-learn mailing list