What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Enumerating through files in Win32

[?] Enumerating through files in Win32
Author: Message:
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [?] Enumerating through files in Win32
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;
}

This post was edited on 10-27-2011 at 10:27 PM by matty.
10-27-2011 09:31 PM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[?] Enumerating through files in Win32 - by SmokingCookie on 10-27-2011 at 07:54 PM
RE: [?] Enumerating through files in Win32 - by matty on 10-27-2011 at 09:31 PM
RE: [?] Enumerating through files in Win32 - by SmokingCookie on 10-29-2011 at 09:37 AM
RE: [?] Enumerating through files in Win32 - by matty on 10-31-2011 at 11:10 AM
RE: [?] Enumerating through files in Win32 - by SmokingCookie on 10-31-2011 at 02:45 PM
RE: [?] Enumerating through files in Win32 - by matty on 10-31-2011 at 02:53 PM
RE: [?] Enumerating through files in Win32 - by SmokingCookie on 10-31-2011 at 03:55 PM
RE: [?] Enumerating through files in Win32 - by matty on 10-31-2011 at 05:36 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On