473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

File System Object Help

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
Jun 27 '08 #1
7 2304
bo**********@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"
Jun 27 '08 #2
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.
Jun 27 '08 #3

<bo**********@heathwallace.comwrote in message
news:4b**********************************@d1g2000h sg.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
Jun 27 '08 #4
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"
Jun 27 '08 #5
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.
:-)
Actually, since we are being pedantic, InStr() does not return a boolean
value: it returns a number signifying the position of the search string
in the to-be-searched string. Your shortcut is relying on the
coincidence that zero corresponds to the value of the boolean false in
vbscript, as well as relying on an implicit conversion of an integer to
a boolean.

It's fortunate that vbscript is no longer being developed so there is no
chance that Instr() will ever be revised to return a zero-based index
for the character position ...

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jun 27 '08 #6
Actually, since we are being pedantic, InStr() does not return a boolean
value: it returns a number signifying the position of the search string
in the to-be-searched string. Your shortcut is relying on the
coincidence that zero corresponds to the value of the boolean false in
vbscript, as well as relying on an implicit conversion of an integer to
a boolean.
Ummm...not, it's not. Read it again:

strInclude = InStr( ",html,asp,php,htm," , "," & extension & "," ) 0

Look at the "0" there at the end.

That's why I noted "Don't need to use an IF test to set a boolean value
based on something that is already a boolean value." That is, the "0"
comparison is already producing the boolean value.

I suppose it would have been clearer to have written it as

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

But since extra parentheses in VBScript cause an extra dummy Variant to be
pushed onto the operator stack, I avoided that. Yeah, I know. Optimizing
the wrong thing.

In reality, of course, there's no reason in his code to even *HAVE* that
strInclude variable. Easier, faster, simpler to just do the IF test and
driectly affect the HTML:

<%
....
for each objFileItem in objFolderContents
fName = objFileItem.Name
extension = Mid(fName, InStrRev(fName,".")+1)
If InStr( ",html,asp,php,htm," , "," & extension & "," ) 0 Then
%>
<a href="<%=fName%>"><%=fName%></a><br>
<%
end if
next
%>
....

But never mind. Getting far off track now.
Jun 27 '08 #7
Old Pedant wrote:
>Actually, since we are being pedantic, InStr() does not return a
boolean value: it returns a number signifying the position of the
search string in the to-be-searched string. Your shortcut is relying
on the coincidence that zero corresponds to the value of the boolean
false in vbscript, as well as relying on an implicit conversion of
an integer to a boolean.

Ummm...not, it's not. Read it again:

strInclude = InStr( ",html,asp,php,htm," , "," & extension & ","
) 0

Look at the "0" there at the end.
Oops, I did miss that, A lot of people think leaving that ">0" bit off is
very smart.

--
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"
Jun 27 '08 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Brian Sabolik | last post by:
I'm not sure if I've broken any Object Oriented rules or not, but ... I have projects in 2 different solutions that need to use each other's methods. Therefore I may have an "update" method in...
9
by: Paul | last post by:
Hi, VB.NET is saying the file I am creating is in use by another process and won't complete its task of moving the file to the specified destination folder. Here is my code (the main bit...
11
by: Skc | last post by:
I have a .txt which has been exported as a .csv from an external source. What i need to do is to import this into SQL2000 (into a table) but I need to do special things on the data: 1. I need to...
7
by: Drew Berkemeyer | last post by:
I've encounted a pretty strange problem and I'm not quite sure what to make of it. I have a web service that consumes an XML file as well as a few other parameters. This web service works fine...
2
by: Mad Scientist Jr | last post by:
i'm trying to read a file byte by byte (and later alter the data and write it to a 2nd file byte by byte) and running into a problem where it seems to keep reading the same byte over and over again...
1
by: apple | last post by:
i try to print image file in a directory using PrintDocument. It will raise printPage event to draw image to the printer. The file will be deleted after print and the directory will be checked...
4
by: News | last post by:
Hi Everyone, The attached code creates client connections to websphere queue managers and then processes an inquiry against them. The program functions when it gets options from the command...
5
by: Hardy Wang | last post by:
Hi all, I am new to WSE 3.0, and currently reading the document shipped with installation. From sample provided (see below), I created WSE service side code, but how can I consume stream returned...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
4
by: taufik | last post by:
hi guys... i new person using vb.net i have some problem in copy a file into specific directory create by user... below is coding that write that may help u all to solve my problem Imports...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.