From: boyd.roberts on
Hello All,

I am trying to generate a list of files in a directory on a website,
which only includes a defined list of file extentions.

Below is my code but i have an issue that this only returns the first
file in my includelist.


<%
Dim objFSO, objFile, objFileitem, objFolder, objFolderContents
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(Server.MapPath("."))
Set objFolderContents = objFolder.Files

for each objFileItem in objFolderContents

includelist = "html, asp, php, htm"
arrInclude = split(includelist, ",")

pos = instr(objFileItem.Name, ".")
extension = mid(objFileItem.Name, pos+1, len(objFileItem.Name)-pos)

strinclude = false

if extension = arrInclude(i) then
strinclude = true
end if

if strinclude = true then
%>
<a href="<%=objFileitem.Name%>"><%=objFileitem.Name%></a><br>
<%
end if
next
%>

Hope someone can show me the errors of my ways.

Many Thanks
From: Bob Barrows [MVP] on
boyd.roberts(a)heathwallace.com wrote:
> Hello All,
>
> I am trying to generate a list of files in a directory on a website,
> which only includes a defined list of file extentions.
>
> Below is my code but i have an issue that this only returns the first
> file in my includelist.
>
>
> <%
> Dim objFSO, objFile, objFileitem, objFolder, objFolderContents
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(Server.MapPath("."))
> Set objFolderContents = objFolder.Files
>
> for each objFileItem in objFolderContents
>
> includelist = "html, asp, php, htm"
> arrInclude = split(includelist, ",")
>
> pos = instr(objFileItem.Name, ".")
> extension = mid(objFileItem.Name, pos+1, len(objFileItem.Name)-pos)
>
> strinclude = false
>
> if extension = arrInclude(i) then

You tell me: what is the value of i here?
What do you think you would see if you did
Response.Write i & "<BR>"

> strinclude = true
> end if
>
> if strinclude = true then
> %>
> <a href="<%=objFileitem.Name%>"><%=objFileitem.Name%></a><br>
> <%
> end if
> next
> %>
>
> Hope someone can show me the errors of my ways.
>
Try this:

includelist = ",html,asp,php,htm,"
if instr(includelist, "," & extension & ",") > 0 then
strinclude = true
else
strinclude = false
end if

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


From: Old Pedant on
> includelist = ",html,asp,php,htm,"
> if instr(includelist, "," & extension & ",") > 0 then
> strinclude = true
> else
> strinclude = false
> end if

Well, since my screen name is indeed old PEDANT...

Why not simply

<%
....
strInclude = InStr( ",html,asp,php,htm," , "," & extension & "," ) > 0
....
%>

Don't need to use an IF test to set a boolean value based on something that
is already a boolean value.


From: Anthony Jones on

<boyd.roberts(a)heathwallace.com> wrote in message
news:4b123ad6-5b82-450c-93b9-e1960156b4a1(a)d1g2000hsg.googlegroups.com...
> Hello All,
>
> I am trying to generate a list of files in a directory on a website,
> which only includes a defined list of file extentions.
>
> Below is my code but i have an issue that this only returns the first
> file in my includelist.
>
>
> <%
> Dim objFSO, objFile, objFileitem, objFolder, objFolderContents
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(Server.MapPath("."))
> Set objFolderContents = objFolder.Files
>
> for each objFileItem in objFolderContents
>
> includelist = "html, asp, php, htm"
> arrInclude = split(includelist, ",")
>
> pos = instr(objFileItem.Name, ".")
> extension = mid(objFileItem.Name, pos+1, len(objFileItem.Name)-pos)
>
> strinclude = false
>
> if extension = arrInclude(i) then
> strinclude = true
> end if
>
> if strinclude = true then
> %>
> <a href="<%=objFileitem.Name%>"><%=objFileitem.Name%></a><br>
> <%
> end if
> next
> %>
>
> Hope someone can show me the errors of my ways.
>

In addition to the help the others have given you should bear in mind that
the following is a legal file name:-

This.is.a.file.htm

Use-

sIncludeList = ",html,asp,php,htm,"

....

sExtension = objFSO.GetExtenstionName(objFileItem.Name)

bInclude = Instr(sIncludeList, "," & sExtension & ",") > 0


--
Anthony Jones - MVP ASP/ASP.NET


From: Bob Barrows [MVP] on
Old Pedant wrote:
>> includelist = ",html,asp,php,htm,"
>> if instr(includelist, "," & extension & ",") > 0 then
>> strinclude = true
>> else
>> strinclude = false
>> end if
>
> Well, since my screen name is indeed old PEDANT...
>
> Why not simply
>
> <%
> ...
> strInclude = InStr( ",html,asp,php,htm," , "," & extension & "," ) > 0
> ...
> %>
>
> Don't need to use an IF test to set a boolean value based on
> something that is already a boolean value.

That's how I would do it, but my goal was to make sure the OP understood
what was going on, not minimizing the number of lines of code. :-)

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"