DirEntries range seems impractical with foreach
Spacen Jasset
spacenjasset at mailrazer.com
Tue Mar 18 02:12:08 PDT 2014
On Tuesday, 18 March 2014 at 08:54:50 UTC, Spacen Jasset wrote:
> On Monday, 17 March 2014 at 20:39:45 UTC, anonymous wrote:
>> On Monday, 17 March 2014 at 09:18:36 UTC, Spacen Jasset wrote:
>>> While trying to use dirEntries range with foreach I
>>> encountered a seemingly unsurmountable problem. The problem
>>> is that an execption is thrown while calling .front() on the
>>> range that dirEntries returnes, which seems to mean it's
>>> impossible to use it with a for loop if you exepect any sort
>>> of 'access denied' or other file exception - which will be
>>> quite common. e.g. in c:\windows
>>>
>>> Is there any way to fix the foreach loop version (a)
>>>
>>>
>>> (a) Can't make this work
>>> foreach (DirEntry e; entries) {
>>>
>>> }
>>> std.file.FileException at std\file.d(2262):
>>> c:/windows\CSC\v2.0.6: Access is denied
>>>
>>>
>>> (b)This works
>>> auto entries = dirEntries(path, spanMode);
>>> while (!entries.empty) {
>>> try {
>>> DirEntry e = entries.front();
>>> //...
>>> entries.popFront();
>>> } catch (FileException e) {
>>> writeln("Skipping something");
>>> }
>>> }
>>
>> b doesn't work in the general case, either. dirEntries throws
>> immediately when the very first entry is not accessible.
>
>
> I see. I raised a bug on this issue
> https://d.puremagic.com/issues/show_bug.cgi?id=12391 Perhaps
> there are some other libraries ideas that can be used.
Boost also has the same problems:
http://www.cplusplus.com/forum/windows/99515/
It occurs to me that exceptions during wide filesystem traversal
are usual rather than the exception.
More information about the Digitalmars-d-learn
mailing list