Removing readonly files on windows with std.file
Vino
akashvino79 at gmail.com
Wed Mar 11 01:54:49 UTC 2020
On Monday, 9 March 2020 at 22:55:10 UTC, Walter Bright wrote:
> On 3/7/2020 12:01 PM, Jonathan Marler wrote:
>> We could modify std.file.remove to be able to remove readonly
>> files,
>
> This is definitely the wrong approach for the default behavior.
>
> It should fail and the app then remove the readonly attribute
> and try again, or the remove() should have a "force"
> non-default option.
I am fine with whatever method this forum decides in implementing
this function, at present I have been using the below code to
remove the read-only attribute and then delete the file
foreach(d; parallel(dFiles[],1)) {
foreach(f; dirEntries(join([`\\?\`,d[0]]),
SpanMode.depth, false)) {
if (f.isFile) { setAttributes(f, 0x80);
remove(f); } else { rmdir(f); } }
rmdirRecurse(d[0]); } }
}
I have been using this code for one of my old project since past
2 year’s and below are my observation.
The above code works for 90% of the time. Meaning we execute this
script via task scheduler on daily basis, it works for few weeks
and error out stating, “Access Denied”.
The execution time is very costly as the above function deletes
TB’s of file daily
So I request you to look into the above 2 point while
implementing this solution
From,
Vino
More information about the Digitalmars-d
mailing list