Knowledge Base: Examples of Recursion Recursively Directory Listing by Using FileSystemObject Examples: Recursively Array Listing by Using VBScript Examples:
Knowledge Base: Examples of Recursion
Recursion: Each item of an expression is generated by repeating a particular definition recursively.
Recursively Directory Listing by Using FileSystemObject
Recursively Directory Listing by Using FileSystemObject.
Examples:
Example of Recursively Directory Listing by Using FileSystemObject.
ASP VbScript Command:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<script runat="server" language="VBScript">
Dim fso, objtemp, fderpar, cnt0
Set fso = CreateObject("Scripting.FileSystemObject")
Set objtemp = fso.CreateFolder("R:\temp0")
Set objtemp = fso.CreateFolder("R:\temp0\temp1")
Set objtemp = fso.CreateFolder("R:\temp0\temp1\temp2")
Set objtemp = fso.CreateFolder("R:\temp0\temp1\temp2\temp3")
Set objtemp = fso.CreateTextFile("R:\temp0\file0.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\file1.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\file2.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\file0.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\file1.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\file2.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\temp2\file0.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\temp2\file1.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\temp2\file2.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\temp2\temp3\file0.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\temp2\temp3\file1.txt")
Set objtemp = fso.CreateTextFile("R:\temp0\temp1\temp2\temp3\file2.txt")
fderpar="R:\temp0"
cnt0=0
Response.Write fderpar&"<br />"
Response.Write LstFder(fderpar,cnt0)
Function LstFder(fder_par,cnt)
dim fso, objfder, colfder, colfile, subfder, subfile, count
Set fso = CreateObject("Scripting.FileSystemObject")
Set objfder = fso.GetFolder(fder_par)
Set colfder = objfder.SubFolders
Set colfile = objfder.Files
count=cnt+1
For Each subfder In colfder
Response.Write PrtArrow(count)&subfder&"--"& count&"<br />"
Call LstFder(subfder,count)
Next
For Each subfile In colfile
Response.Write PrtArrow(count)&subfile&"<br />"
Next
End Function
Function PrtArrow(cnt)
Dim count
count=cnt
Do While count>0
count=count-1
Response.Write "-->"
loop
End Function
</script>
</body>
</html>
Example of Recursively Array Listing by Using VBScript.last updated 11Jul2016
ASP VbScript Command:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Sample Page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<script runat="server" language="VBScript">
Dim OriArry, NewArry
OriArry=Array("s","i","d","e","w","a","y","o","u","t")
Response.Write "Original Array"
Response.Write LstArry(OriArry,0,0,UBound(OriArry))&"<br /> "
For i = LBound(OriArry) to UBound(OriArry)
OriArry(i)=array(i,OriArry(i))
Next
Response.Write "First Modified Array"
Response.Write LstArry(OriArry,0,0,UBound(OriArry))&"<br /> "
OriArry(0)="0"
OriArry(3)(1)=array(OriArry(3)(1),"34")
OriArry(6)(1)=array(OriArry(6)(1),"34","65","34","65","34","65","34","65","34","65","34","65")
OriArry(6)(1)(1)=array(OriArry(3)(1),"34")
Response.Write "Second Modified Array"
Response.Write LstArry(OriArry,0,0,UBound(OriArry))&"<br /> "
Function LstArry(Ori_Arry,lvl,cnt,sze)
Dim i, j, k, l
j=lvl
k=cnt
l=sze
Response.Write "<br /> "
call PrtArrow(j)
Response.Write "["
flag=0
For i = LBound(Ori_Arry) to UBound(Ori_Arry)
If k<l and j>0 Then
flag=1
End If
If IsArray(Ori_Arry(i)) Then
call LstArry(Ori_Arry(i),j+1,i,UBound(Ori_Arry))
Else
Response.Write Ori_Arry(i)
If i<>UBound(Ori_Arry) Then
Response.Write ", "
End If
End If
Next
Response.Write "]"
If flag=1 then
Response.Write ","
End If
End Function
Function PrtArrow(cnt)
Dim count
count=cnt
Do While count>0
count=count-1
Response.Write "-->"
loop
End Function
</script>
</body>
</html>