quote:
Originally posted by whiz
I'd like to ask a related question. How can you delete a file? And does it work with folders?
No offence but you should start trying the easy stuff yourself first then post if you cannot get it to work...
js code:
function DeleteFile(lpstrFile) {
return Interop.Call('kernel32', 'DeleteFileW', lpstrFile) !== 0;
}
To remove a directory:
js code:
/* do not include trailing slashes, pass the path as c:\\test */
function RemoveDirectory(sPath) {
var WIN32_FIND_DATA = Interop.Allocate(592);
var hSearch = Interop.Call('kernel32', 'FindFirstFileW', sPath+'\\*.*', WIN32_FIND_DATA);
var hResult;
while(hResult != 0){
if(!(WIN32_FIND_DATA.ReadDWORD(0) & 0x10 /* FILE_ATTRIBUTE_DIRECTORY */)){
Interop.Call('kernel32', 'DeleteFileW', sPath+'\\'+WIN32_FIND_DATA.ReadString(44));
} else {
RemoveDirectory(sPath+WIN32_FIND_DATA.ReadString(44));
Interop.Call('kernel32', 'RemoveDirectoryW', '\\\\?\\'+sPath+'\\'+WIN32_FIND_DATA.ReadString(44));
}
hResult = Interop.Call('kernel32', 'FindNextFileW', hSearch, WIN32_FIND_DATA)
}
Interop.Call('kernel32', 'FindClose', hSearch);
}