Member_2_6492660_1
asked on
ASP Code to List Folders Only
ASP Classic
IIS 6
Would like to know how I can just list all the folders that are under one folder on my server
Topfolder
folder1
folder2
folder3
etc
Have a total of over 2600 folders under this main folder.
This is s far as I got
<%
dim fs,f
set fs=Server.CreateObject("Sc ripting.Fi leSystemOb ject")
Thanks for any help
IIS 6
Would like to know how I can just list all the folders that are under one folder on my server
Topfolder
folder1
folder2
folder3
etc
Have a total of over 2600 folders under this main folder.
This is s far as I got
<%
dim fs,f
set fs=Server.CreateObject("Sc
Thanks for any help
If you need it customized let me know and I can do it for you when I get home and nor on my phone :)
ASKER
Thanks Big Monty
checking it out now and going to eat diner
checking it out now and going to eat diner
No problem. Again let me know if you get stuck and I'll gladly help you out
ASKER
Big Monty
I m back now
This code produces a list of all files in every folder.
I would just like to list only the folder names similar to a dir /ad /b
thoughts
I m back now
This code produces a list of all files in every folder.
I would just like to list only the folder names similar to a dir /ad /b
thoughts
Then just call the sub ListFolders and comment or take out the code altogether. If you're still having problems post your code so far with this new code added in
ASKER
Not sure what to remove
Tried a few options keep getting line errors
Tried a few options keep getting line errors
OK I ought to be home in an hour, I'll get you the code then
ASKER
Ok great thanks
ok let's try something like this. put the following code into a blank asp page and run it, and make sure you set the correct path on the first line
<%
ListFolder "c:\folderToList\" '-- this can be any physical path your web site has access to
Sub ListFolder(path)
Dim fs, rootPath
Set fs = Server.CreateObject("Scripting.FileSystemObject")
rootPath = Replace(path, Server.MapPath("/"), "") & "\"
ListFolderContents fs.GetFolder(path), PathEncode(rootPath)
End Sub
Sub ListFolderContents(folder, relativePath)
Dim child
Say "<ul>"
Say "<li><div class=""folder"">" & h(folder.Name) & "</div>"
For Each child In folder.SubFolders
ListFolderContents child, relativePath & PathEncode(child.Name) & "/"
Next
'--***********uncomment the lines below to list the files as well
' relativePath = h(relativePath)
' For Each child In folder.Files
' If Not IsHidden(child) Then
' Say "<li><a href=""" & relativePath & h(PathEncode(child.Name)) & """>" & h(child.Name) & "</a></li>"
' End If
' Next
' Say "</ul>"
End Sub
Function PathEncode(s)
' this creates a more correct variant of what Server.URLEncode would do
PathEncode = Replace(s, "\", "/")
PathEncode = Server.URLEncode(PathEncode)
PathEncode = Replace(PathEncode, "+", "%20")
PathEncode = Replace(PathEncode, "%2F", "/")
PathEncode = Replace(PathEncode, "%2E", ".")
PathEncode = Replace(PathEncode, "%5F", "_")
End Function
' -- Helper Functions / Shorthands ---------------------------------------
Sub Say(s)
Response.Write s & vbNewLine
End Sub
Function h(s)
h = Server.HTMLEncode(s)
End Function
%>
ASKER
Big Monty
That's now listing the folders and the sub folders not the files
I was needing this one next.
But the output is indented way too far to the right
check it out
www.tomsmp3.com/music4.asp
Only need first level folders
music
mp3musicalbums
artist a
artist b
artist c
2600 more
That's now listing the folders and the sub folders not the files
I was needing this one next.
But the output is indented way too far to the right
check it out
www.tomsmp3.com/music4.asp
Only need first level folders
music
mp3musicalbums
artist a
artist b
artist c
2600 more
i just tested out the following code and it displayed all files and folders on my web site. I set my path to the root of my site, you can set it to whatever:
<%@language=vbscript%>
<%
ListFolder Server.MapPath("/") '-- this can be any physical path your web site has access to
Sub ListFolder(path)
Dim fs, rootPath
Set fs = Server.CreateObject("Scripting.FileSystemObject")
rootPath = Replace(path, Server.MapPath("/"), "") & "\"
ListFolderContents fs.GetFolder(path), PathEncode(rootPath)
End Sub
Sub ListFolderContents(folder, relativePath)
Dim child
Say "<ul>"
Say "<li><div class=""folder"">" & h(folder.Name) & "</div>"
For Each child In folder.SubFolders
ListFolderContents child, relativePath & PathEncode(child.Name) & "/"
Next
relativePath = h(relativePath)
For Each child In folder.Files
Say "<li><a href=""" & relativePath & h(PathEncode(child.Name)) & """>" & h(child.Name) & "</a></li>"
Next
Say "</ul>"
End Sub
Function PathEncode(s)
' this creates a more correct variant of what Server.URLEncode would do
PathEncode = Replace(s, "\", "/")
PathEncode = Server.URLEncode(PathEncode)
PathEncode = Replace(PathEncode, "+", "%20")
PathEncode = Replace(PathEncode, "%2F", "/")
PathEncode = Replace(PathEncode, "%2E", ".")
PathEncode = Replace(PathEncode, "%5F", "_")
End Function
' -- Helper Functions / Shorthands ---------------------------------------
Sub Say(s)
Response.Write s & vbNewLine
End Sub
Function h(s)
h = Server.HTMLEncode(s)
End Function
%>
the line
ListFolder Server.MapPath("/")
is where you want to set your path. If you use a physical path, don't user Server.MapPath.
ListFolder Server.MapPath("/")
is where you want to set your path. If you use a physical path, don't user Server.MapPath.
ASKER
Response object error 'ASP 0251 : 80004005'
Response Buffer Limit Exceeded
/music4.asp, line 0
Execution of the ASP page caused the Response Buffer to exceed its configured limit.
fixed that by
<%Response.Buffer = false%>
but it lists all files I only need folder names
Take a look at it www.tomsmp3.com/music4.asp
Response Buffer Limit Exceeded
/music4.asp, line 0
Execution of the ASP page caused the Response Buffer to exceed its configured limit.
fixed that by
<%Response.Buffer = false%>
but it lists all files I only need folder names
Take a look at it www.tomsmp3.com/music4.asp
flush out the buffer in each loop:
<%@language=vbscript%>
<%
Response.Buffer = false
ListFolder Server.MapPath("/") '-- this can be any physical path your web site has access to
Sub ListFolder(path)
Dim fs, rootPath
Set fs = Server.CreateObject("Scripting.FileSystemObject")
rootPath = Replace(path, Server.MapPath("/"), "") & "\"
ListFolderContents fs.GetFolder(path), PathEncode(rootPath)
End Sub
Sub ListFolderContents(folder, relativePath)
Dim child
Say "<ul>"
Say "<li><div class=""folder"">" & h(folder.Name) & "</div>"
For Each child In folder.SubFolders
ListFolderContents child, relativePath & PathEncode(child.Name) & "/"
Response.Flush
Next
relativePath = h(relativePath)
For Each child In folder.Files
Say "<li><a href=""" & relativePath & h(PathEncode(child.Name)) & """>" & h(child.Name) & "</a></li>"
Response.Flush
Next
Say "</ul>"
End Sub
Function PathEncode(s)
' this creates a more correct variant of what Server.URLEncode would do
PathEncode = Replace(s, "\", "/")
PathEncode = Server.URLEncode(PathEncode)
PathEncode = Replace(PathEncode, "+", "%20")
PathEncode = Replace(PathEncode, "%2F", "/")
PathEncode = Replace(PathEncode, "%2E", ".")
PathEncode = Replace(PathEncode, "%5F", "_")
End Function
' -- Helper Functions / Shorthands ---------------------------------------
Sub Say(s)
Response.Write s & vbNewLine
End Sub
Function h(s)
h = Server.HTMLEncode(s)
End Function
%>
ASKER
•mp3musicalbums
¿
!!!
¿
Louden Up Now
¿01-Louden Up Now-When The Going Gets Tough, The Tough Gets Krazee.mp3
Response object error 'ASP 0159 : 80004005'
Buffering Off
/music4.asp, line 31
Buffering must be on.
that is still listing the files too
I only need the !!! to be displayed
¿
!!!
¿
Louden Up Now
¿01-Louden Up Now-When The Going Gets Tough, The Tough Gets Krazee.mp3
Response object error 'ASP 0159 : 80004005'
Buffering Off
/music4.asp, line 31
Buffering must be on.
that is still listing the files too
I only need the !!! to be displayed
<%@language=vbscript%>
<%
Response.Buffer = false
ListFolder "m:\music\mp3musicalbums" '-- this can be any physical path your web site has access to
Sub ListFolder(path)
Dim fs, rootPath
Set fs = Server.CreateObject("Scripting.FileSystemObject")
rootPath = Replace(path, Server.MapPath("/"), "") & "\"
ListFolderContents fs.GetFolder(path), PathEncode(rootPath)
End Sub
Sub ListFolderContents(folder, relativePath)
Dim child
Say "<ul>"
Say "<li><div class=""folder"">" & h(folder.Name) & "</div>"
For Each child In folder.SubFolders
ListFolderContents child, relativePath & PathEncode(child.Name) & "/"
Response.Flush
Next
relativePath = h(relativePath)
For Each child In folder.Files
Say "<li><a href=""" & relativePath & h(PathEncode(child.Name)) & """>" & h(child.Name) & "</a></li>"
Response.Flush
Next
Say "</ul>"
End Sub
Function PathEncode(s)
' this creates a more correct variant of what Server.URLEncode would do
PathEncode = Replace(s, "\", "/")
PathEncode = Server.URLEncode(PathEncode)
PathEncode = Replace(PathEncode, "+", "%20")
PathEncode = Replace(PathEncode, "%2F", "/")
PathEncode = Replace(PathEncode, "%2E", ".")
PathEncode = Replace(PathEncode, "%5F", "_")
End Function
' -- Helper Functions / Shorthands ---------------------------------------
Sub Say(s)
Response.Write s & vbNewLine
End Sub
Function h(s)
h = Server.HTMLEncode(s)
End Function
[code]<%@language=vbscript%>
<%
Response.Buffer = false
ListFolder "m:\music\mp3musicalbums" '-- this can be any physical path your web site has access to
Sub ListFolder(path)
Dim fs, rootPath
Set fs = Server.CreateObject("Scripting.FileSystemObject")
rootPath = Replace(path, Server.MapPath("/"), "") & "\"
ListFolderContents fs.GetFolder(path), PathEncode(rootPath)
End Sub
Sub ListFolderContents(folder, relativePath)
Dim child
Say "<ul>"
Say "<li><div class=""folder"">" & h(folder.Name) & "</div>"
For Each child In folder.SubFolders
ListFolderContents child, relativePath & PathEncode(child.Name) & "/"
Response.Flush
Next
relativePath = h(relativePath)
For Each child In folder.Files
Say "<li><a href=""" & relativePath & h(PathEncode(child.Name)) & """>" & h(child.Name) & "</a></li>"
Response.Flush
Next
Say "</ul>"
End Sub
Function PathEncode(s)
' this creates a more correct variant of what Server.URLEncode would do
PathEncode = Replace(s, "\", "/")
PathEncode = Server.URLEncode(PathEncode)
PathEncode = Replace(PathEncode, "+", "%20")
PathEncode = Replace(PathEncode, "%2F", "/")
PathEncode = Replace(PathEncode, "%2E", ".")
PathEncode = Replace(PathEncode, "%5F", "_")
End Function
' -- Helper Functions / Shorthands ---------------------------------------
Sub Say(s)
Response.Write s & vbNewLine
End Sub
Function h(s)
h = Server.HTMLEncode(s)
End Function
%>
i'm not sure I'm following, first you say you want just the folders, then you say you want the files as well, i'm a bit confused...try the code below on just one of your subfolders and see if that works. then try the main folder and set the first line to
Response.Buffer = true
Response.Buffer = true
<%@language=vbscript%>
<%
Response.Buffer = false
ListFolder "m:\music\mp3musicalbums" '-- this can be any physical path your web site has access to
Sub ListFolder(path)
Dim fs, rootPath
Set fs = Server.CreateObject("Scripting.FileSystemObject")
rootPath = Replace(path, Server.MapPath("/"), "") & "\"
ListFolderContents fs.GetFolder(path), PathEncode(rootPath)
End Sub
Sub ListFolderContents(folder, relativePath)
Dim child
Say "<ul>"
Say "<li><div class=""folder"">" & h(folder.Name) & "</div>"
For Each child In folder.SubFolders
ListFolderContents child, relativePath & child.Name & "/"
Response.Flush
Next
relativePath = h(relativePath)
For Each child In folder.Files
Say "<li><a href=""" & relativePath & child.Name & """>" & child.Name & "</a></li>"
Response.Flush
Next
Say "</ul>"
End Sub
Function PathEncode(s)
' this creates a more correct variant of what Server.URLEncode would do
PathEncode = Replace(s, "\", "/")
PathEncode = Server.URLEncode(PathEncode)
PathEncode = Replace(PathEncode, "+", "%20")
PathEncode = Replace(PathEncode, "%2F", "/")
PathEncode = Replace(PathEncode, "%2E", ".")
PathEncode = Replace(PathEncode, "%5F", "_")
End Function
' -- Helper Functions / Shorthands ---------------------------------------
Sub Say(s)
Response.Write s & vbNewLine
End Sub
Function h(s)
h = Server.HTMLEncode(s)
End Function
%>
ASKER
ASKER
Your latest code
•mp3musicalbums
¿
!!!
¿
Louden Up Now
¿01-Louden Up Now-When The Going Gets Tough, The Tough Gets Krazee.mp3
Response object error 'ASP 0159 : 80004005'
Buffering Off
/music4.asp, line 31
Buffering must be on.
•mp3musicalbums
¿
!!!
¿
Louden Up Now
¿01-Louden Up Now-When The Going Gets Tough, The Tough Gets Krazee.mp3
Response object error 'ASP 0159 : 80004005'
Buffering Off
/music4.asp, line 31
Buffering must be on.
ASKER
I worked this up
But I get this
Microsoft VBScript runtime error '800a01a8'
Object required: 'WScript'
/music4.asp, line 8
No little VB
<%@language=vbscript%>
<%Response.Buffer = false%>
<%
Dim strFolders
strRoot = "m:\music\mp3musicalbums"
Set objFSO = CreateObject("Scripting.FileSystemObject")
FindDirectories(strRoot)
WScript.Echo strfolders
Sub FindDirectories(input)
Set objFolder = objFSO.GetFolder(input)
Set colSubFolders = objFolder.SubFolders
For Each Folder In colSubFolders
strFolders = strFolders & Replace(Folder.Path,Folder.Drive,"") & ";"
FindDirectories(Folder.Path)
Next
End Sub
%>
But I get this
Microsoft VBScript runtime error '800a01a8'
Object required: 'WScript'
/music4.asp, line 8
No little VB
ASKER
Big Monty
this works from my windows 7 computer (see attached file)
But when I do this
I get this
Microsoft VBScript runtime error '800a01a8'
Object required: 'Wscript'
/music4.asp, line 9
test.txt
this works from my windows 7 computer (see attached file)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("M:\MUSIC\MP3MUSICALBUMS")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next
But when I do this
<%@language=vbscript%>
<%Response.Buffer = false%>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("M:\MUSIC\MP3MUSICALBUMS")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
Wscript.Echo objSubfolder.Name, objSubfolder.Size
Next
%>
I get this
Microsoft VBScript runtime error '800a01a8'
Object required: 'Wscript'
/music4.asp, line 9
test.txt
ASKER
Big Monty
New code needed to change wscript.echo to response.write
Check it out www.tomsmp3.com/music4.asp
I got the information I need but now I need to parse it out onto separate lines with a checkbox on each line.
Long day for me heading to sleep now early to raise.
Any ideas let me know.
Thanks
New code needed to change wscript.echo to response.write
<%@language=vbscript%>
<%Response.Buffer = false%>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("M:\MUSIC\MP3MUSICALBUMS")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
response.write(objSubfolder.Name)
Next
%>
Check it out www.tomsmp3.com/music4.asp
I got the information I need but now I need to parse it out onto separate lines with a checkbox on each line.
Long day for me heading to sleep now early to raise.
Any ideas let me know.
Thanks
that's pretty much the same code I offered up, except without the file names. either way if its working, that's all that matters :)
to get the checkboxes in, use the following code, which assigns the folder name as the value for each checkbox:
now, when you post the data to another page, since all of checkboxes are named chkFolders, you'll do a single Request.Form("chkFolders") which will give you a comma delimited string of all of the options that are checked
to get the checkboxes in, use the following code, which assigns the folder name as the value for each checkbox:
<%@language=vbscript%>
<%Response.Buffer = true%>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("M:\MUSIC\MP3MUSICALBUMS")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
folderName = objSubfolder.Name
Response.Write "<p><input checkbox name="chkFolders" value='" & folderName & "' /></p>"
Next
%>
now, when you post the data to another page, since all of checkboxes are named chkFolders, you'll do a single Request.Form("chkFolders")
ASKER
Big Daddy
Just tested
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/music4.asp, line 10
Response.Write "<p><input checkbox name="chkFolders" value='" & folderName & "' /></p>"
-------------------------- ---------- -----^
Just tested
Microsoft VBScript compilation error '800a0401'
Expected end of statement
/music4.asp, line 10
Response.Write "<p><input checkbox name="chkFolders" value='" & folderName & "' /></p>"
--------------------------
<%@language=vbscript%>
<%Response.Buffer = true%>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("M:\MUSIC\MP3MUSICALBUMS")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
folderName = objSubfolder.Name
Response.Write "<p><input checkbox name="chkFolders" value='" & folderName & "' /></p>"
Next
%>
sorry about that, try this:
<%@language=vbscript%>
<%Response.Buffer = true%>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("M:\MUSIC\MP3MUSICALBUMS")
Set colSubfolders = objFolder.Subfolders
For Each objSubfolder in colSubfolders
folderName = objSubfolder.Name
Response.Write "<p><input checkbox name='chkFolders' value='" & folderName & "' /></p>"
Next
%>
ASKER
Thanks we are getting close
check out the site
www.tomsmp3.com/muic4.asp
It placed the names of the folders inside the check box and since the check box is not so big the full folder name can not be seen.
I need the check box then folder name
check out the site
www.tomsmp3.com/muic4.asp
It placed the names of the folders inside the check box and since the check box is not so big the full folder name can not be seen.
I need the check box then folder name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Big Monty
That's it
Now I can code a submit button so when you click on the check box it will list all the songs or albums from that artist
going out now will try later
Thanks again
That's it
Now I can code a submit button so when you click on the check box it will list all the songs or albums from that artist
going out now will try later
Thanks again
ASKER
Big Monty
Back online
Just got back my daughter just had her second Baby proud Pop Pop
Would like to modify the code a bit for a new page
What we did was list all the artists
Now I would like to list all the artists and the albums
M:\Music\mp3musicalbums>cd the doors
M:\Music\mp3musicalbums\Th e Doors>dir
Volume in drive M is Music
Volume Serial Number is 0C03-7207
Directory of M:\Music\mp3musicalbums\Th e Doors
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1967
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1968
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1969
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1971
04/09/2014 11:18 AM <DIR> L.A. Woman
04/09/2014 11:18 AM <DIR> Live At The Hollywood Bowl
04/09/2014 11:18 AM <DIR> Morrison Hotel
04/09/2014 08:41 PM <DIR> The Best of the Doors
04/09/2014 11:19 AM <DIR> The Doors
04/09/2014 11:19 AM <DIR> The Matrix- San Fran '67
Like this
Back online
Just got back my daughter just had her second Baby proud Pop Pop
Would like to modify the code a bit for a new page
What we did was list all the artists
Now I would like to list all the artists and the albums
M:\Music\mp3musicalbums>cd
M:\Music\mp3musicalbums\Th
Volume in drive M is Music
Volume Serial Number is 0C03-7207
Directory of M:\Music\mp3musicalbums\Th
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1967
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1968
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1969
04/09/2014 11:18 AM <DIR> Billboard Top 100 - 1971
04/09/2014 11:18 AM <DIR> L.A. Woman
04/09/2014 11:18 AM <DIR> Live At The Hollywood Bowl
04/09/2014 11:18 AM <DIR> Morrison Hotel
04/09/2014 08:41 PM <DIR> The Best of the Doors
04/09/2014 11:19 AM <DIR> The Doors
04/09/2014 11:19 AM <DIR> The Matrix- San Fran '67
Like this
ASKER
Big Monty
Thanks again
I will open a new question later
Thanks again
I will open a new question later
Open in new window