Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Search for files in a directory - output if it doesnt exist

Moderators: larsivi kris

Posted: 09/01/08 11:57:49

I am totally new to D (I've only ever played with PHP and VB it's sort of a large step up..)

I was wondering how to go about doing this..

Basically I want to create a program that searches through a directory (recursively) for files that contain a user defined search string.

If it comes across a directory that DOESN'T contain a file that matches the search string, I want it to output the FOLDER NAME it couldn't find the file in.


Author Message

Posted: 09/07/08 17:11:17

I can give you some hints as to what pieces of Tango you need to get this working. :)

For console input and output, look at and Cin.copyln() to read, Stdout.formatln() to write stuff.

Then you need to figure out how to use the module.

I think it goes something like this (not tested):

const char[] lookFor = "xyz.txt";
FileFolder folder = new FileFolder(startingDir);
foreach (subdir; folder.tree) {
    if (!subdir.file(lookFor).exists)

Relevant docs:

Posted: 09/07/08 22:31:58

Nice one, Torhu :)

To emit the folder name too, use this:

Stdout.formatln ("{} does not contain {}", subdir, lookFor);