digitalmars.D.learn - DirEntries range seems impractical with foreach
- Spacen Jasset (24/24) Mar 17 2014 While trying to use dirEntries range with foreach I encountered a
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/9) Mar 17 2014 There has been past discussions on this. What version of dmd are you
- Mike Wey (8/17) Mar 17 2014 The problem is that dirEntries is trying to transverse into a directory
- anonymous (3/27) Mar 17 2014 b doesn't work in the general case, either. dirEntries throws
- Spacen Jasset (4/37) Mar 18 2014 I see. I raised a bug on this issue
- Spacen Jasset (5/43) Mar 18 2014 Boost also has the same problems:
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 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"); } }
Mar 17 2014
On 03/17/2014 02:18 AM, 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()There has been past discussions on this. What version of dmd are you using? The following fix may have already fixed this issue. If not, please open another bug report: http://d.puremagic.com/issues/show_bug.cgi?id=8298 Ali
Mar 17 2014
On 03/17/2014 02:54 PM, Ali Çehreli wrote:On 03/17/2014 02:18 AM, Spacen Jasset wrote:The problem is that dirEntries is trying to transverse into a directory for which the application doesn't have any access permission, this is a different issue from 8298. But should dirEntries simply skip the directories it doesn't have access to, or should the user be notified somehow? -- Mike WeyWhile trying to use dirEntries range with foreach I encountered a seemingly unsurmountable problem. The problem is that an execption is thrown while calling .front()There has been past discussions on this. What version of dmd are you using? The following fix may have already fixed this issue. If not, please open another bug report: http://d.puremagic.com/issues/show_bug.cgi?id=8298 Ali
Mar 17 2014
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 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.
Mar 17 2014
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: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.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 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.
Mar 18 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: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.On Monday, 17 March 2014 at 09:18:36 UTC, Spacen Jasset wrote: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.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 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.
Mar 18 2014