Solved

FSO Get Folder Names

Posted on 2003-11-07
18
1,218 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
  • 9
  • 5
  • 4
18 Comments
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 250 total points
Comment Utility
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 250 total points
Comment Utility
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
Comment Utility
Fritz slow down I'm trying to catch you up. ;o) (And welcome :o)
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
Comment Utility
Oh yeah congrats on the half million mark :o)
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Why thank you sir!

FtB
0
 

Author Comment

by:flfmmqp
Comment Utility
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
Comment Utility
What is the path to the folder that has all of your sub folders?

FtB
0
 

Author Comment

by:flfmmqp
Comment Utility
I tried this but it did not work.

Set strPath = "C:\Inetpub\wwwroot\aresearch\AR_documentation"
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:flfmmqp
Comment Utility
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
Comment Utility
Remove the Set - should just be
strPath = "C:\Inetpub\wwwroot\aresearch\AR_documentation"
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
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
Comment Utility
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
Comment Utility
It also works if I do this instead:

strPath = "D:\My Documents\InProgress"

FtB
0
 

Author Comment

by:flfmmqp
Comment Utility
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
Comment Utility
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
Comment Utility
Yep they work now.  Which is awesome.  Thanks again.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
Comment Utility
Glad to have helped,

FtB
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now