quote:
Originally posted by matty
js code:
function RemoveDirectory(sPath) {
var FO_DELETE = 0x3
var FOF_ALLOWUNDO = 0x40;
var SHFILEOPSTRUCT = Interop.Allocate(30);
var strPath = Interop.Allocate(sPath.length*2+2);
strPath.WriteString(0, sPath);
with (SHFILEOPSTRUCT) {
WriteDWORD(0, 0);
WriteDWORD(4, FO_DELETE);
WriteDWORD(8, strPath.DataPtr);
//WriteWORD(16, FOF_ALLOWUNDO); // If you want the files to be sent to the recycle bin uncomment the following
}
if ( Interop.Call('shell32', 'SHFileOperationW', SHFILEOPSTRUCT) > 0 ) TraceWin32Error();
}
function TraceWin32Error(){
var LastError = Interop.GetLastError();
if(LastError != 0) {
var MsgBuffer = Interop.Allocate(1024);
Interop.Call("Kernel32", "FormatMessageW", 0x1000, 0, LastError, 0, MsgBuffer, 1024, 0);
Debug.Trace(MsgBuffer.ReadString(0));
}
}
The folder and files remain, along with two errors. One in the debugger...
quote:
Originally posted by JavaScript Debugger
code:
The handle is invalid.
...and a Windows alert (title: "Error Deleting File or Folder", message: "Cannot delete file: Cannot read from the source file or disk.").
EDIT: No... you don't need trailing slashes. Let me try again.
EDIT 2: It works! And it has a Windows confirm dialog box. Thank you!