That's a very specific question, but I'll break it down.
This is Bug.js
, it conditionally removes a directory and recreates it (effectively, creating it empty):
var fso = new ActiveXObject("Scripting.FileSystemObject");
DIROutputFull = "C:\\Test"
if(fso.FolderExists(DIROutputFull)) fso.DeleteFolder(DIROutputFull);
fso.CreateFolder(DIROutputFull);
Bug.js
is run like cscript.exe Bug.js
, and it usually works - unless C:\Test
pre-exists and I have a Windows Explorer window open in C:\Test
. This is kind of expected, because one might think deleting that directory might fail. By contrast, re-creating it is what fails.
So this is the sequence of events:
cscript.exe Bug.js
cscript.exe Bug.js
cscript.exe Bug.js
[...]
cscript.exe Bug.js
start C:\Test
cscript.exe Bug.js
cscript.exe Bug.js
And this is the output:
[...]
C:\>cscript.exe Bug.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
C:\>start C:\Test
C:\>cscript.exe Bug.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Bug.js(4, 1) Microsoft JScript runtime error: Permission denied
C:\>cscript.exe Bug.js
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Note permission denied in line four, not three: C:\Test
is in fact deleted, but not re-created.
Why is that? Note also that this very minimal use case is just what I was able to reproduce. I run into this problem much more often than I'd like, and I am using a script that I am willing to modify as it is updated often from an external source.
Some information on my environment:
C:\>ver
Microsoft Windows [Version 10.0.16299.309]
C:\>cscript.exe /?
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
What else would be relevant?