The rmdir()
function fails if the folder contains any files. I can loop through all of the the files in the directory with something like this:
As per this source;
Save some time, if you want to clean a directory or delete it and you're on windows.
Use This:
chdir ($file_system_path);
exec ("del *.* /s /q");
You can use other DEL syntax, or any other shell util. You may have to allow the service to interact with the desktop, as that's my current setting and I'm not changing it to test this.
Else you could find an alternative method here.