0

I've written some code to display my bookmarks on IE8. The code works fine except the array of favorites I should have ("favs") as output exists but is empty (when I put "favs" in the developer tools console I get {...}).

var fso, favs = [];
var favString="";
function GetFavourites(Folder) {
    var FavFolder = fso.GetFolder(Folder);
    //Gets Favourite Names & URL's for given folder.
    var files = new Enumerator(FavFolder.Files);
    for (; !files.atEnd(); files.moveNext()) {
        var fil = files.item();
        if (fil.Type == "Internet Shortcut") {
            var textReader = fso.OpenTextFile(fil.Path, 1, false, -2);
            var favtext = textReader.ReadAll();
            var start = favtext.indexOf("URL", 16);
            var stop = favtext.indexOf("\n", start);
            favString = fil.Name.replace(/.url/, "");
            favString += ":URL:";
            //to separate favourite name & favorite URL
            favString += favtext.substring(start + 4, stop - 1);
            favs.push(favString);
        }
    }
    //Checks any subfolder exists
    var subfolders = new Enumerator(FavFolder.SubFolders);
    for (; !subfolders.atEnd(); subfolders.moveNext()) {
        var folder = subfolders.item();
        GetFavourites(folder.Path);
    }
}
function Import() {
    try {
        fso = new ActiveXObject("Scripting.FileSystemObject");
        if (fso !== null) {
            //Create windows script shell object to access Favorites folder in user system.
            var object = new ActiveXObject("WScript.Shell");
            var favfolderName = object.SpecialFolders("Favorites");
            if (favString === "") {
                GetFavourites(favfolderName);
            }
        }
    }
    catch (err) {
        alert("Security settings to be modified in your browser ");
    }
}
4
  • Have you tried typing favs[0] in your console? As far as i know, IE8's debugging tool cannot display the contents of an array of orbject. Commented May 12, 2011 at 9:32
  • @freaktm Yes I've tried; I've tried also to go through the array with a For structure. But I'm pretty sure the array is empty because I get 0 with favs.length Commented May 12, 2011 at 9:34
  • Have you checked your favourites folder (C:\Users\Bruno\Favorites) isn't empty? =) Commented May 12, 2011 at 9:43
  • @Andy E Yes, I've checked and my favorites are there :-) Commented May 12, 2011 at 9:50

1 Answer 1

1

I've found where my mistake is : I forgot I was using IE in French so the test "if (fil.Type == "Internet Shortcut")" doesn't work; I must replace "Internet Shortcut" with the French equivalent "Raccourci Internet". :-))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.