Advice on : rmdirRecurse and setAttributes in Windows

WebFreak001 d.forum at webfreak.org
Sun Apr 22 18:10:27 UTC 2018


On Saturday, 21 April 2018 at 18:39:02 UTC, Vino wrote:
> Hi All,
>
>   The function rmdirRecurse does not work in Windows if the 
> file has the READ ONLY permission, so to over come this issue, 
> i have written the below function to set the permission on file 
> and folder using the function "setAttributes" , so can any one 
> advice me whether the below code is fine or what are the other 
> ways to achieve the same.
>
>
> auto aPrivileges(T)(T df)
> if(df[0].isDir) {
>             auto sDir = Array!string(dirEntries(join([`\\?\`, 
> df[0]]), SpanMode.depth).filter!(a => a.isDir).map!(a => 
> (a.name)));
>             auto sFile = Array!string(dirEntries(join([`\\?\`, 
> df[0]]), SpanMode.depth).filter!(a => a.isFile).map!(a => 
> (a.name)));
>             foreach(sD; parallel(sDir[], 1)) { 
> setAttributes(sD.toUTF16, 66); }
>             foreach(sF; parallel(sFile[], 1)) { 
> setAttributes(sF.toUTF16, 666); }
>             }
>         else { setAttributes(df[0].toUTF16, 666); }
> }
>
> From,
> Vino.B

This seems very hacky, you should instead just replicate the 
behaviour of rmdirRecurse. This is what I did in the dub library 
which does this thing for you: 
https://github.com/WebFreak001/rm-rf/blob/master/source/rm/rf.d


More information about the Digitalmars-d-learn mailing list