www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Command Line Application in D

reply "TJB" <broughtj gmail.com> writes:
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
Aug 04 2014
parent reply maarten van damme via Digitalmars-d-learn writes:
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
Aug 04 2014
parent reply "TJB" <broughtj gmail.com> writes:
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?
Aug 04 2014
next sibling parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
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>"); } }
Aug 04 2014
parent "TJB" <broughtj gmail.com> writes:
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>");
 	}
 }
Aug 05 2014
prev sibling parent "Mike James" <foo bar.com> writes:
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>-
Aug 04 2014