digitalmars.D.learn - rmdirRecurse vs readonly
- Lemonfiend (2/2) Dec 24 2013 std.file.rmdirRecurse refuses to remove readonly files.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (26/28) Dec 24 2013 Call std.file.setAttributes() first, which has apparently been added
- Lemonfiend (3/32) Dec 25 2013 Haha, how very timely.
std.file.rmdirRecurse refuses to remove readonly files. How would I go about deleting them anyway?
Dec 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
Dec 24 2013
On Tuesday, 24 December 2013 at 16:11:15 UTC, Ali Çehreli wrote:On 12/24/2013 04:13 AM, Lemonfiend wrote:Haha, how very timely. Thanks! And merry xmas :)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 25 2013