Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileSystemObject question 4

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
Greetings,

I want to use the FileSystemObject method to pull out a list of sound files (.wav) from my server folder and put into an array. Then I would like to use this array to populate <embed> tags. I have about 61 files and I would like to do this dynamically instead of typing each embed tag. I just can't figure out how to do it. I'm just not familiar enough with the FSO method. I would appreciate any suggestions. Thanks.
 
Mel,

Here you go.. You'll need to change the path to the folder or use the mappath method if you don't know the exact path.

<%@ Language=VBScript %>
<% Option Explicit %>
<%
dim i
dim objFileSys
dim theFolder
dim theFiles
set objFileSys = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
set theFolder = objFileSys.GetFolder(&quot;c:\test&quot;)
set theFiles = TheFolder.Files
FOR EACH i IN theFiles
Response.Write i & &quot;<br>&quot;
NEXT
%>

Now that will simply write the files to the browser window to show you how the FileSystemObject works with file collections in folders. To dynamically write that into your <embed> tags, You don't need to create an array, just initialize the FSO before writing the <embed> tags, then do something like this.

<%
FOR EACH i IN theFiles
%>
<embed src=&quot;<%=i.Name%>&quot;>
<%
NEXT
%>

Notice I used the Name property. Otherwise if you ran the initial test, you'll notice that i returns the path and the file name. Using the Name property just writes the file name.

Hope this helps.

ToddWW :)
 
to get just the .wav files:

<%
FOR EACH i IN theFiles
filearray = split(i.Name, &quot;.&quot;)
If filearray(1) = &quot;wav&quot; Then
%>
<embed src=&quot;<%=i.Name%>&quot;>
<%
End If
NEXT
%>

 
If I could've typed faster, I would've taken the other words right out of your mouth too, ToddWW. :cool:

You're both welcome!
 
Outstanding job, it works exactly as I needed it to. Thanks again so much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top