www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - rmdirRecurse vs readonly

reply "Lemonfiend" <lemon fie.nd> writes:
std.file.rmdirRecurse refuses to remove readonly files.

How would I go about deleting them anyway?
Dec 24 2013
parent reply =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
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
Dec 24 2013
parent "Lemonfiend" <lemon fie.nd> writes:
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 :)
Dec 25 2013