Command Line Application in D

Rikki Cattermole via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 4 19:52:20 PDT 2014


On 5/08/2014 10:03 a.m., TJB wrote:
> On Monday, 4 August 2014 at 21:58:09 UTC, maarten van damme via
> Digitalmars-d-learn wrote:
>> I am a little bit confused as to what you want.
>> There is a command line example at dlang.org, and there exists a program
>> (rdmd) that compiles several D files and runs them.
>> http://dlang.org/rdmd.html
>
> Sorry. I wasn't very clear. Say I want to find all of the files that
> have a certain extension within a directory and process them somehow at
> the command line. How could I do that?

Just a little something I made for you. Untested of course. But takes an 
argument from cli, which is a glob. Foreach file under current working 
directory, if its a file write out processing.

(I gave std.stdio an alias because std.file and std.stdio conflict for 
some symbols)

import std.file;
import stdio = std.stdio;

void main(string[] args) {
	if (args.length == 2) {
		foreach(entry; dirEntries(".", args[1], SpanMode.Depth)) {
			if (isDir(entry.name)) {
			} else if (isFile(entry.name)) {
				stdio.writeln("Processing " ~ entry.name);
			}
		}
	} else {
		stdio.writeln("Arguments: <glob>");
	}
}


More information about the Digitalmars-d-learn mailing list