js code:
function GetDirectoryStructure(sPath, sPattern, IncludePath) {
_debug.getfuncname(arguments);
var aFileNames = [];
var Win32_Find_Data = Interop.Allocate(592);
var hSearch = Interop.Call('kernel32', 'FindFirstFileW', '\\\\?\\' + sPath + sPattern, Win32_Find_Data);
var hResult;
while (hResult !== 0) {
if (!(Win32_Find_Data.ReadDWORD(0) & 0x10 /* FILE_ATTRIBUTE_DIRECTORY */ & 0x4 /* FILE_ATTRIBUTE_SYSTEM */) &&
Win32_Find_Data.ReadString(44).charAt(0) !== '.') {
aFileNames.push((IncludePath ? sPath : '') + Win32_Find_Data.ReadString(44));
}
hResult = Interop.Call('kernel32', 'FindNextFileW', hSearch, Win32_Find_Data)
}
Interop.Call('kernel32', 'FindClose', hSearch);
return aFileNames;
}
That is what we did for SS5. You only need to close the first handle, not all of them.
The problem is that you keep overwriting hFind. hFind should be the handle to the directory not the next file you keep finding. At least that is what it appears. No WLM/Plus! installed to check.
Do something like this:
js code:
FileSystem.EnumerateFiles = function(Directory) {
var ret = new Array();
>>> var result;<<<
>>> var hFind = (result = this.FindFirstFile(Directory)).hFind;<<<
if(result.hFind === 0) {
result.WIN32_FIND_DATA.Size = 0;
return ret;
}
ret.push(result);
do {
>>> result = this.FindNextFile(hFind);<<<
ret.push(result);
} while(result.hFind !== 0);
return ret;
}