Thread overview
Command Line Application in D
Aug 04, 2014
TJB
Aug 04, 2014
maarten van damme
Aug 04, 2014
TJB
Aug 05, 2014
Rikki Cattermole
Aug 05, 2014
TJB
Aug 05, 2014
Mike James
August 04, 2014
I am trying to build some simple command line applications that I have written in python as a way to learn D. Can you give some examples for me? For instance, I think I remember once seeing somewhere in the documentation an example that took several D files and compiled them all by running some kind of system command.

I much appreciate your help!

TJB
August 04, 2014
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


2014-08-04 23:20 GMT+02:00 TJB via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com>:

> I am trying to build some simple command line applications that I have written in python as a way to learn D. Can you give some examples for me? For instance, I think I remember once seeing somewhere in the documentation an example that took several D files and compiled them all by running some kind of system command.
>
> I much appreciate your help!
>
> TJB
>


August 04, 2014
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?
August 05, 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>");
	}
}
August 05, 2014
On Monday, 4 August 2014 at 22:03:24 UTC, 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?

Have a look at the function dirEntries in std.file.

regards,

-<mike>-
August 05, 2014
This is exactly what I was thinking.  Thanks so much for your
help!

TJB

> 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>");
> 	}
> }