try
{
    var km_aanvraag = {from: [ 1082, 1084, 1086, 1090, 1092, 1094, 1096, 1098, 1100
    						 , 1102, 1104, 1106, 1108, 1141, 1221, 1222, 1223, 1224
    						 , 1225, 1226, 1227, 1228, 1229, 1232, 1233, 1235
    						 , 1240, 1242, 1244, 1245, 1247, 1249, 1281, 1324
    						 , 1343, 1344, 1412, 1561, 1641, 1662, 1709, 1761
    						 , 1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770
    						 , 1771, 1772, 1773, 1774, 1775, 1776, 1777,  281
    						 , 2169, 2170, 2145, 2141
                             ]
                      ,to :2441
                      };
    var km_klacht   = {from: [ 1250
                             ]
                      ,to: 2461
                      };
    var km_storing  = {from: [ 1049, 1053, 1057, 1061, 1064, 1069, 1251, 1252, 1254
    						 , 1255, 1257, 1258, 1259, 1260, 1261, 1264, 1268
    						 , 1269, 1270, 1429, 1891, 2021, 2022, 2023
    						 , 2024, 2025, 2061, 2161, 2162, 2163, 2164, 2165
    						 , 2166, 2171, 2172, 2173, 2174, 2175, 2176
    						 , 2177, 2178, 2179, 2180, 2181, 2182, 2183
    						 , 2184, 2185, 2186, 2187, 2188, 2189, 2190
    						 , 2191, 2192,  681,  942
                             ]
                      ,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);
}