Removing readonly files on windows with std.file
Patrick Schluter
Patrick.Schluter at bbox.fr
Sun Mar 8 09:04:34 UTC 2020
On Saturday, 7 March 2020 at 22:51:46 UTC, Dominikus Dittes
Scherkl wrote:
> On Saturday, 7 March 2020 at 20:01:07 UTC, Jonathan Marler
> wrote:
>> We could modify std.file.remove to be able to remove readonly
>> files, but maybe there's use cases where people want the
>> removal to fail if it is marked as readonly?
>
> I always thought "readonly" was intended to protect from
> "modification" not from "deletion", so simply making the
> function consistent with the explorer would be the right thing
> to do.
> It's like a "const" variable: you cannot change its value, but
> of course you should be able to free the memory it occupies if
> it goes out of scope or is otherwise detectable not used
> anymore.
Microsoft says [1]
FILE_ATTRIBUTE_READONLY
A file that is read-only. Applications can read the file, but
cannot write to it or delete it. This attribute is not honored on
directories.
So the behaviour of del or the explorer is violating theur own
definition.
[1]:
https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants
More information about the Digitalmars-d
mailing list