remove file access denied(remove broke)

Alex sascha.orlov at gmail.com
Fri Sep 14 13:16:07 UTC 2018


On Friday, 14 September 2018 at 08:32:48 UTC, Josphe Brigmo wrote:
> 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.

´´´
void main()
{
	import std.file : exists, read, remove;
	import std.stdio : File;
	import std.uuid : randomUUID;
	import std.file : tempDir;
	import std.path : dirSeparator;

	string tFileName = tempDir ~ dirSeparator ~ randomUUID.toString;
	
	File(tFileName, "w").close;
	assert(tFileName.exists);
	assert(tFileName.read.length == 0);
	tFileName.remove;
	assert(!tFileName.exists);
}
´´´

This works for me. And what does not for you?


More information about the Digitalmars-d-learn mailing list