Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

FSO Get Folder Names

Posted on 2003-11-07
18
Medium Priority
?
1,225 Views
Last Modified: 2012-06-21
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
Comment
Question by:flfmmqp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
18 Comments
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 1000 total points
ID: 9701544
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
 
LVL 58

Assisted Solution

by:Gary
Gary earned 1000 total points
ID: 9701551
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
 
LVL 58

Expert Comment

by:Gary
ID: 9701557
Fritz slow down I'm trying to catch you up. ;o) (And welcome :o)
0
Technology Partners: 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!

 
LVL 46

Expert Comment

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


FtB
0
 
LVL 58

Expert Comment

by:Gary
ID: 9701615
Oh yeah congrats on the half million mark :o)
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9701684
Why thank you sir!

FtB
0
 

Author Comment

by:flfmmqp
ID: 9701784
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9701838
What is the path to the folder that has all of your sub folders?

FtB
0
 

Author Comment

by:flfmmqp
ID: 9701894
I tried this but it did not work.

Set strPath = "C:\Inetpub\wwwroot\aresearch\AR_documentation"
0
 

Author Comment

by:flfmmqp
ID: 9701933
I'm getting this:

Microsoft VBScript runtime error '800a01a8'

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

/aresearch/ar_documents.asp, line 61
0
 
LVL 58

Expert Comment

by:Gary
ID: 9701995
Remove the Set - should just be
strPath = "C:\Inetpub\wwwroot\aresearch\AR_documentation"
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9702003
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9702023
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9702055
It also works if I do this instead:

strPath = "D:\My Documents\InProgress"

FtB
0
 

Author Comment

by:flfmmqp
ID: 9702572
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9702599
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
 

Author Comment

by:flfmmqp
ID: 9702656
Yep they work now.  Which is awesome.  Thanks again.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 9702700
Glad to have helped,

FtB
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question