Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1226
  • Last Modified:

FSO Get Folder Names

I want to get all folder names with in a specific folder and put those names into an option box for the user to select from.  I am doing this already with files but I don't want to have to have worry about adding new folders manually to the previous option box.  

I know this can be done but how?  The option box I want to fill is called "cboDocFolders" and I want to see all of the folder names that are in the "AR_documentation" folder in the cboDocFolders.  For this many points I am looking for code.

This is what I have now:

<HTML>
<HEAD>
<Meta Http-EQUIV="expires" Content="0">
<meta NAME="GENERATOR" Content="Microsoft FrontPage 3.0">
<title></title>
</HEAD>
<BODY>


<%
'***********************************************************
'* Step 1: Display the type of item to select from
'***********************************************************
If Len(Request.Form("FormAction")) = 0 Then

%>

<form action="ar_documents.asp" method="post" name="frmDisplay">
  <input type="hidden" name="FormAction" value="Step2"><input type="hidden"
  name="txtDivision" ><input type="hidden" name="txtCurrentBid" ><input
  type="hidden" name="txtItemName" >

<TABLE border=0 cellPadding=1 cellSpacing=1 style="WIDTH: 526px; HEIGHT: 94px"
width="75%">
 
  <TR>
    <TD><STRONG><EM>Use the Box Below to Choose the Type of documentation you would like to look at:
    </EM></STRONG></TD></TR>
  <TR>
    <TD>

       
<SELECT name=cboDocFolders>
   <OPTION value="Systems" selected>Systems</OPTION>
   <OPTION value="Other">Other</OPTION>    
</SELECT>

     <script language=vbscript>
     
     Sub cboDocFolders_OnClick()
     'Save the Item name the user selects by clicking on the combo box
     frmDisplay.txtDivision.value =  _
     frmDisplay.cboDocFolders(frmDisplay.cboDocFolders.selectedIndex).value
     End Sub

     </script>

    </SELECT></TD></TR>
  <TR>
    <P><TD height="60"><INPUT name=btnSubmit type=submit value="  Next  "></TD></P></TR></TABLE>
<P></P>

<%
'*****************************************************************
'* Step 2: Get the Store the User would like to view
'*****************************************************************

ElseIf Request.Form("FormAction") = "Step2" Then

     Dim strFolder
     Set strFolder = Request.Form("cboDocFolders")
' File System Object
     Dim fso
          Set fso = Server.CreateObject("Scripting.FileSystemObject")

     ' "PDF" Folder
     Dim folder
          Set folder = fso.GetFolder("C:\Inetpub\wwwroot\aresearch\AR_documentation\" & strFolder & "")
          'Set folder = fso.GetFolder("C:\Inetpub\wwwroot\Space_SQ\Stores\" & division & "")

%>

<FORM action="" method=post id=form1 name=form1>
<input type="hidden" name="txtDivisionName" value="<%=Request.Form("txtdivision")%>">
<%response.write "<STRONG><EM>Use the Box Below to Choose your Store: </EM></STRONG>"
response.write "<br><STRONG><EM>A new web page will open after you have selected your store.</EM></STRONG><br>"
%>
<SELECT id=select1 name=select1 onChange="javascript:window.open(this.value,'groovywindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,height=' + WinHeight + 'width=' + WinWidth + 'copyhistory=no')">

<script language="javascript">
if (window.screen) {
   var WinWidth = screen.availWidth;
   var WinHeight = screen.availHeight;
    WinWidth = WinWidth - 10;
    WinHeight = WinHeight - 25;
   }
</script>


<%If folder.Size > 0 Then %>


<% For Each file In folder.Files%>
<option VALUE= "AR_documentation/<%=strFolder%>/<%=file.Name%>"><% Response.write file.Name%></option>
          <%Next
     Else
          Response.Write "No pdf available"
     End If
%>


<%
Set folder = Nothing
Set fso = nothing


          %>
</SELECT>

</FORM>

<input type=Button value="&lt; Back" onclick="location.href='http://ho01wb01/aresearch/ar_documents.asp';">
<%
'<input type=Button value="&lt; Back" onclick="location.href='http://united-way/space_sq/ARSpace.asp';" id=Button1 name=Button1>
end if
%>


<P>&nbsp;
  <P></P>
  <P></P></P></TABLE></form>

</BODY>
</HTML>
0
flfmmqp
Asked:
flfmmqp
  • 9
  • 5
  • 4
2 Solutions
 
fritz_the_blankCommented:
Okay, here is the first bit:

Dim objFSO, objSubfolder, objFolder,strPath
'set strPath to the path of your folder

set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder(strPath)
for each objSubfolderin objFolder.subfolders
  response.write("<option>" & objSubfolder.name & "</option>")
next
set objFolder=Nothing
set objFSO = Nothing
0
 
GaryCommented:
Place this code at the beginning somewhere then just write the variable selectbox where you need it displayed
<%
sPP = Server.MapPath("rootfoldername")

Set fso = CreateObject("Scripting.filesystemObject")
Set f = fso.Getfolder(sPP)

Set ff = f.Subfolders

selectbox="<select name=folders>"
For Each f1 in ff
selectbox=selectbox & "<option>" & f1.name
Next
selectbox=selectbox &"</select>"
response.write selectbox
%>
0
 
GaryCommented:
Fritz slow down I'm trying to catch you up. ;o) (And welcome :o)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
fritz_the_blankCommented:
It is the first time that I have ever been on top for both lists! I am trying to savour the moment...


FtB
0
 
GaryCommented:
Oh yeah congrats on the half million mark :o)
0
 
fritz_the_blankCommented:
Why thank you sir!

FtB
0
 
flfmmqpAuthor Commented:
Can you give me an example of the strPath?

Thanks for the quick response by both of you.  I will try both to see which one works best for me.

Thanks again.
0
 
fritz_the_blankCommented:
What is the path to the folder that has all of your sub folders?

FtB
0
 
flfmmqpAuthor Commented:
I tried this but it did not work.

Set strPath = "C:\Inetpub\wwwroot\aresearch\AR_documentation"
0
 
flfmmqpAuthor Commented:
I'm getting this:

Microsoft VBScript runtime error '800a01a8'

Object required: '[string: "C:\Inetpub\wwwroot\a"]'

/aresearch/ar_documents.asp, line 61
0
 
GaryCommented:
Remove the Set - should just be
strPath = "C:\Inetpub\wwwroot\aresearch\AR_documentation"
0
 
fritz_the_blankCommented:
The path should look something like:

D:\My Documents\inProgress

BTW, there is a typo in my code:

for each objSubfolderin objFolder.subfolders


should be:

for each objSubfolder in objFolder.subfolders
0
 
fritz_the_blankCommented:
Here is the code that I am using in its entirety:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
      <title>Untitled</title>
</head>
<body>
<%
Dim objFSO, objSubfolder, objFolder,strPath
'set strPath to the path of your folder
strPath =server.MapPath("../inProgress")
set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder(strPath)
Response.write("<select name=strFolders>")
for each objSubfolder in objFolder.subfolders
  response.write("<option>" & objSubfolder.name & "</option>")
next
Response.write("</select>")
set objFolder=Nothing
set objFSO = Nothing
%>
</body>
</html>


FtB
0
 
fritz_the_blankCommented:
It also works if I do this instead:

strPath = "D:\My Documents\InProgress"

FtB
0
 
flfmmqpAuthor Commented:
I would like to thank both of you for your help.  I actually used bits and pieces of the information both of you gave me in the end.  So I would like to split up the points between you.  How do I do that?
0
 
fritz_the_blankCommented:
When you accept the answer, there should be an option to specify an assist, and then you can split the points that way.

So, the good news is that things work? Great!

FtB
0
 
flfmmqpAuthor Commented:
Yep they work now.  Which is awesome.  Thanks again.
0
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 9
  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now