codepilot
February 22nd, 2005, 04:34 AM
Hello folks,
I have a huge problem with an enumerator object in my JScript function that should return the maximum directory depth.
Here's the code (please watch out for my comments, which mark the problem I'm having):
function getDirDeepness(path, current)
{
Response.Write("<b>getDirDeepness: " + path + " " + current + "</b><br>");
var highest = current;
var fileSystem = new ActiveXObject('Scripting.FileSystemObject');
if(fileSystem == null)
return -1;
if(fileSystem.folderExists(path))
{
folderList = new Enumerator(fileSystem.GetFolder(path).SubFolders)
//HERE: ALL SUB-DIRECTORIES ARE LISTED CORRECTLY!
while(!folderList.atEnd())
{
Response.Write("In list: " + folderList.item() + "<br>");
folderList.moveNext();
}
folderList.moveFirst();
if(folderList && !folderList.atEnd())
{
var next;
//HERE: This loop is only ran once; folderList.atEnd() returns immediatelly true after the first loop! WHY????
while(!folderList.atEnd())
{
var subfolder = folderList.item();
next = getDirDeepness(subfolder, current+1);
Response.Write(subfolder + " " + current + " " + next + " " + highest + "<br>");
if(highest < next)
highest = next;
Response.Write(folderList.atEnd() + "<br>");
folderList.moveNext();
}
}
}
return highest;
}
And this is a the debug-output I get:
getDirDeepness: C:\WEB\rms\reports 0
In list: C:\WEB\rms\reports\test1
In list: C:\WEB\rms\reports\test2
getDirDeepness: C:\WEB\rms\reports\test1 1
In list: C:\WEB\rms\reports\test1\marco
In list: C:\WEB\rms\reports\test1\matthias
In list: C:\WEB\rms\reports\test1\sebastian
In list: C:\WEB\rms\reports\test1\slaid
getDirDeepness: C:\WEB\rms\reports\test1\marco 2
In list: C:\WEB\rms\reports\test1\marco\marco's pkw
In list: C:\WEB\rms\reports\test1\marco\steffi
getDirDeepness: C:\WEB\rms\reports\test1\marco\marco's pkw 3
C:\WEB\rms\reports\test1\marco\marco's pkw 2 3 2
true
C:\WEB\rms\reports\test1\marco 1 3 1
true
C:\WEB\rms\reports\test1 0 3 0
true
Why does it immedieatelly free the recoursion when I only read the first item from my Enumerator?
Please help!
Thank you!
~codepilot
I have a huge problem with an enumerator object in my JScript function that should return the maximum directory depth.
Here's the code (please watch out for my comments, which mark the problem I'm having):
function getDirDeepness(path, current)
{
Response.Write("<b>getDirDeepness: " + path + " " + current + "</b><br>");
var highest = current;
var fileSystem = new ActiveXObject('Scripting.FileSystemObject');
if(fileSystem == null)
return -1;
if(fileSystem.folderExists(path))
{
folderList = new Enumerator(fileSystem.GetFolder(path).SubFolders)
//HERE: ALL SUB-DIRECTORIES ARE LISTED CORRECTLY!
while(!folderList.atEnd())
{
Response.Write("In list: " + folderList.item() + "<br>");
folderList.moveNext();
}
folderList.moveFirst();
if(folderList && !folderList.atEnd())
{
var next;
//HERE: This loop is only ran once; folderList.atEnd() returns immediatelly true after the first loop! WHY????
while(!folderList.atEnd())
{
var subfolder = folderList.item();
next = getDirDeepness(subfolder, current+1);
Response.Write(subfolder + " " + current + " " + next + " " + highest + "<br>");
if(highest < next)
highest = next;
Response.Write(folderList.atEnd() + "<br>");
folderList.moveNext();
}
}
}
return highest;
}
And this is a the debug-output I get:
getDirDeepness: C:\WEB\rms\reports 0
In list: C:\WEB\rms\reports\test1
In list: C:\WEB\rms\reports\test2
getDirDeepness: C:\WEB\rms\reports\test1 1
In list: C:\WEB\rms\reports\test1\marco
In list: C:\WEB\rms\reports\test1\matthias
In list: C:\WEB\rms\reports\test1\sebastian
In list: C:\WEB\rms\reports\test1\slaid
getDirDeepness: C:\WEB\rms\reports\test1\marco 2
In list: C:\WEB\rms\reports\test1\marco\marco's pkw
In list: C:\WEB\rms\reports\test1\marco\steffi
getDirDeepness: C:\WEB\rms\reports\test1\marco\marco's pkw 3
C:\WEB\rms\reports\test1\marco\marco's pkw 2 3 2
true
C:\WEB\rms\reports\test1\marco 1 3 1
true
C:\WEB\rms\reports\test1 0 3 0
true
Why does it immedieatelly free the recoursion when I only read the first item from my Enumerator?
Please help!
Thank you!
~codepilot