iterate over a directory, dealing with permission errors

2015-09-18 Thread John Colvin via Digitalmars-d
Posting here instead of learn because I think it uncovers a design flaw void main(string[] args) { import std.file : dirEntries, SpanMode; import std.stdio : writeln; foreach(file; dirEntries(args[1], SpanMode.depth)) writeln(file.name); } Modify this program such that it wi

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Robert burner Schadek via Digitalmars-d
On Friday, 18 September 2015 at 11:35:45 UTC, John Colvin wrote: Posting here instead of learn because I think it uncovers a design flaw void main(string[] args) { import std.file : dirEntries, SpanMode; import std.stdio : writeln; foreach(file; dirEntries(args[1], SpanMode.depth))

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Adrian Matoga via Digitalmars-d
On Friday, 18 September 2015 at 11:35:45 UTC, John Colvin wrote: Posting here instead of learn because I think it uncovers a design flaw void main(string[] args) { import std.file : dirEntries, SpanMode; import std.stdio : writeln; foreach(file; dirEntries(args[1], SpanMode.depth))

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Adrian Matoga via Digitalmars-d
On Friday, 18 September 2015 at 11:54:32 UTC, Robert burner Schadek wrote: http://dlang.org/phobos/std_exception.html#.handle foreach(file; dirEntries(args[1], SpanMode.depth) .handle!(Exception, RangePrimitive.front, (e, r) => DirEntry())) { writeln(file.name); } change Exception

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread John Colvin via Digitalmars-d
On Friday, 18 September 2015 at 11:54:32 UTC, Robert burner Schadek wrote: On Friday, 18 September 2015 at 11:35:45 UTC, John Colvin wrote: Posting here instead of learn because I think it uncovers a design flaw void main(string[] args) { import std.file : dirEntries, SpanMode; import

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Robert burner Schadek via Digitalmars-d
On Friday, 18 September 2015 at 12:17:25 UTC, John Colvin wrote: That's neat, didn't know about std.exception.handle It is at least a year old. I created it because I had a range that threw, and there was nothing to keep a range going or reenter it. Unfortunately, I think there are two pr

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread John Colvin via Digitalmars-d
On Friday, 18 September 2015 at 12:27:37 UTC, Robert burner Schadek wrote: On Friday, 18 September 2015 at 12:17:25 UTC, John Colvin wrote: That's neat, didn't know about std.exception.handle It is at least a year old. I created it because I had a range that threw, and there was nothing to ke

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Robert burner Schadek via Digitalmars-d
On Friday, 18 September 2015 at 12:42:26 UTC, John Colvin wrote: Yes, but implicit in this being an OK solution for people is that no-one ever reorganises the internals of DirIteratorImpl. I guess One could use handle to deal with *all* the range primitives as a defensive countermeasure. yes,

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Meta via Digitalmars-d
On Friday, 18 September 2015 at 12:42:26 UTC, John Colvin wrote: well, creating a DirEntry is not a range operation. handle can't help you there. Yup :( I think you could use std.exception.ifThrown in this case. foreach(file; dirEntries(args[1], SpanMode.depth) .ifThrown(Di

Re: iterate over a directory, dealing with permission errors

2015-09-18 Thread Dmitry Olshansky via Digitalmars-d
On 18-Sep-2015 15:03, Adrian Matoga wrote: On Friday, 18 September 2015 at 11:35:45 UTC, John Colvin wrote: Posting here instead of learn because I think it uncovers a design flaw void main(string[] args) { import std.file : dirEntries, SpanMode; import std.stdio : writeln; foreach(

Re: iterate over a directory, dealing with permission errors

2015-09-19 Thread Spacen Jasset via Digitalmars-d
On Friday, 18 September 2015 at 14:35:39 UTC, Dmitry Olshansky wrote: On 18-Sep-2015 15:03, Adrian Matoga wrote: On Friday, 18 September 2015 at 11:35:45 UTC, John Colvin wrote: Posting here instead of learn because I think it uncovers a design flaw void main(string[] args) { import std.f