remove file access denied(remove broke)

Josphe Brigmo JospheBrigmo at gmail.com
Fri Sep 14 08:32:48 UTC 2018


On Friday, 14 September 2018 at 04:48:09 UTC, Norm wrote:
> On Thursday, 13 September 2018 at 23:25:24 UTC, Josphe Brigmo 
> wrote:
>> I am trying to remove a file
>>
>> remove(filename);
>>
>> and I get an access denied!
>>
>> I can remove it from explorer just fine.
>>
>> I am able to remove other files but there should be no reason 
>> why the file can't be removed in this case.
>>
>> All I am doing to mess with the file is reading it's contents 
>> right before to do a file compare(I am removing the file if it 
>> is a duplicate).
>>
>> Does read() lock the file at all? (maybe the lock is 
>> persisting just long enough to make the remove fail?
>>
>> Since I can delete the file outside the program and since the 
>> filename is valid(I copied and pasted it to remove it to 
>> check), This seems like a D problem.
>
> Do you have the file open when you call remove? If so close the 
> file handle before the remove call. If you can post a stripped 
> down version of your code it would also help.
>
> bye,
> Norm

No, I use read, there is no file handles. Pointless to post code 
because it won't offer much. Also, I have security privileges.

I simply read the file to compare it's contents then I try to 
remove the file if it had the same contents and it says it is 
invalid. I also, of course, check that it exist and is a file.

This is all I'm doing that is related to file reading and I 
cannot remove the file(but can read it and such).

So, I'm really wondering if read locks the file but doesn't 
release it in time.

Using lockHunder shows the file isn't locked but the directory 
is(Probably because I'm iterating through it.

Seems it is an error with remove, using executeShell works fine:

auto ls = executeShell(`del /F /Q "`~fn~`"`);

which does not give an error but remove(fn) does.

Seems remove is broke.




More information about the Digitalmars-d-learn mailing list