try
{
    var km_aanvraag = {from: [ 282, 301, 302, 303, 304, 305, 306, 307, 308, 309
                             , 313, 314, 361, 362, 603, 604, 841, 901,1181,1236
                             ,1239,1241,1243,1246,1282,1301
                             ]
                      ,to :2441
                      };
    var km_klacht   = {from: [
                             ]
                      ,to: 2461
                      };
    var km_storing  = {from: [ 209, 210, 321, 421, 441, 561, 562, 606, 621, 623
                             , 641, 661, 662, 664, 781, 821, 861, 962,1021,1051
                             ,1055,1059,1062,1063,1065,1066,1067,1068,1070,1143
                             ,1145,1162,1253,1256,1262,1263,1322,1346,1348,1581
                             ]
                      ,to: 2462
                      };

    var km_list = [km_aanvraag, km_klacht, km_storing];
    var del_list = [];

    var max_log_prio = 2;
    var folder = ".";

    folder = folder.replace(/\//g,"\\");
    WScript.Echo("Folder: " + folder);

    fso = new ActiveXObject("Scripting.FileSystemObject");
    var fk_1 = fso.GetFolder(folder);
    var fc_1 = new Enumerator(fk_1.SubFolders);
    for (; !fc_1.atEnd(); fc_1.moveNext())
    {   // Alle meldingen gegroepeerd per 1000.
        folder = fc_1.item().name;
        if (folder.search("__NEW__") > 0 )
        {
            log_this("", folder, 1);
        }
        else
        {
            log_this("", folder, 1);

            var fk_2 = fso.GetFolder(folder);
            var fc_2 = new Enumerator(fk_2.SubFolders);
            for (; !fc_2.atEnd(); fc_2.moveNext())
            {   // Alle meldingen
                folder = fc_1.item().name + "/" +fc_2.item().name;
                log_this("", folder, 1);

                var fk_3 = fso.GetFolder(folder);
                var fc_3 = new Enumerator(fk_3.SubFolders);
                for (; !fc_3.atEnd(); fc_3.moveNext())
                {   // Alle kenmerken
                    folder = fc_1.item().name + "/" +fc_2.item().name + "/" + fc_3.item().name;
                    log_this("", folder, 1);
                    for (i=0; i<km_list.length; i++)
                    {
                        var m_kenmerk = km_list[i];
                        for (j=0; j<m_kenmerk.from.length; j++)
                        {
                            var b_kenmerk = m_kenmerk.from[j];
                            var map_from  = fc_1.item().name + "/" +fc_2.item().name + "/" + b_kenmerk;
                            var map_to    = fc_1.item().name + "/" +fc_2.item().name + "/" + m_kenmerk.to;
                            if (b_kenmerk == fc_3.item().name)
                            {
                                log_this("Kenmerk bestand", b_kenmerk, 2);
                                // Maak eventueel de map aan.
                                if (!fso.FolderExists(map_to))
                                {
                                    log_this("Create ", map_to, 2);
                                    fso.CreateFolder(map_to);
                                    log_this("created", map_to, 2);
                                }
                                //verplaats bestand van form naar to
                                var fk_4 = fso.GetFolder(map_from);
                                var fc_4 = new Enumerator(fk_4.files);
                                for (; !fc_4.atEnd(); fc_4.moveNext())
                                {
                                    var filename = fc_4.item().name;
                                    log_this("Move file", filename, 2);
                                    var file = fso.GetFile(map_from + "/" + filename);
                                    file.Move(map_to + "/");
                                    log_this("", "File is moved successfully from " + map_from + "/" + filename + "\n"
                                               + "                             to " + map_to   + "/" + filename, 2);
                                }
                                //verwijder map from
                                //markeer map voor verwijderen.
                                //(niet al verwijderen, anders komt de emnumerate van de kenmerken in de war)
                                del_list.push(map_from);
                            }

                        }
                    }


                }
                //verwijder overbodige mappen
                for (m=0; m<del_list.length; m++)
                {
                    var del_map = del_list[m];
                    if (fso.FolderExists(del_map))
                    {
                        fso.deleteFolder(del_map);
                        log_this("Folder", del_map + " deleted", 2);
                    }
                }
            }
        }
    }
}
catch (e)
{
    WScript.Echo("Serieuze fout: " + e.description)
    WScript.Quit(1);
}


function log_this(prefix, msg, prio)
{
    var prio = (prio ? prio : 1);
    if (prio <= max_log_prio)
        WScript.Echo(prefix + (prefix ? ": " : "") + msg);
}