Thread overview
rmdirRecurse vs readonly
Dec 24, 2013
Lemonfiend
Dec 24, 2013
Ali Çehreli
Dec 25, 2013
Lemonfiend
December 24, 2013
std.file.rmdirRecurse refuses to remove readonly files.

How would I go about deleting them anyway?
December 24, 2013
On 12/24/2013 04:13 AM, Lemonfiend wrote:
> std.file.rmdirRecurse refuses to remove readonly files.
>
> How would I go about deleting them anyway?

Call std.file.setAttributes() first, which has apparently been added just three days ago: :)


https://github.com/D-Programming-Language/phobos/blob/master/std/file.d#L971

If you can't work with git head version of dmd, then do what it does yourself, depending on your platform:

void setAttributes(in char[] name, uint attributes)
{
    version (Windows)
    {
        cenforce(SetFileAttributesW(std.utf.toUTF16z(name), attributes), name);
    }
    else version (Posix)
    {
        assert(attributes <= mode_t.max);
        cenforce(!chmod(toStringz(name), cast(mode_t)attributes), name);
    }
}

For example, if you are on Linux:

import core.sys.posix.sys.stat;
import std.conv;

// ...

    chmod("/my/file", cast(mode_t)octal!777)

Ali

December 25, 2013
On Tuesday, 24 December 2013 at 16:11:15 UTC, Ali Çehreli wrote:
> On 12/24/2013 04:13 AM, Lemonfiend wrote:
>> std.file.rmdirRecurse refuses to remove readonly files.
>>
>> How would I go about deleting them anyway?
>
> Call std.file.setAttributes() first, which has apparently been added just three days ago: :)
>
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/file.d#L971
>
> If you can't work with git head version of dmd, then do what it does yourself, depending on your platform:
>
> void setAttributes(in char[] name, uint attributes)
> {
>     version (Windows)
>     {
>         cenforce(SetFileAttributesW(std.utf.toUTF16z(name), attributes), name);
>     }
>     else version (Posix)
>     {
>         assert(attributes <= mode_t.max);
>         cenforce(!chmod(toStringz(name), cast(mode_t)attributes), name);
>     }
> }
>
> For example, if you are on Linux:
>
> import core.sys.posix.sys.stat;
> import std.conv;
>
> // ...
>
>     chmod("/my/file", cast(mode_t)octal!777)
>
> Ali

Haha, how very timely.

Thanks! And merry xmas :)