Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File Include Loop?

Posted on 2006-06-27
7
Medium Priority
?
205 Views
Last Modified: 2013-11-18
I'm wondering if there is a way to loop through the files in a folder and include each file.  For example

say I have /includes, and in it are db.inc, print.inc, email.inc

I want to be able to do something along these lines

For each file in folder
  <!--#include virtual='/includes/"&file.Name&"'-->
Next

is it possible?
0
Comment
Question by:kevp75
  • 4
  • 3
7 Comments
 
LVL 6

Accepted Solution

by:
inviser earned 1000 total points
ID: 16997201
This is not possible, the  '<!--#include' statement is preprocessor command, meaning all include statements are executed before any asp.

However, whatever you are trying to accomplish, I'm sure it can be done. Give me some more details and I'll help you out.
0
 
LVL 25

Author Comment

by:kevp75
ID: 16997230
not sure how much more detailed I can be.

I have in my /webroot a folder called /includes, in it are all my include files, they contain all the functions I use throughout my site.

all I'm wondering is if there is a way to loop through the content in /includes to see if any files exist, and if they do include them.

for example:

set fso = createobject("scripting.filesystemobject")
  set fol = fso.GetFolder(server.mappath("/includes/")
    set files = fol.Files
      For each File in files
        response.write("<!--#include virtual=""/includes/" & File.Name & """-->") 'what about using server.execute?
      Next
    set files = nothing
  set fol = nothing
set fso = nothing
0
 
LVL 6

Expert Comment

by:inviser
ID: 16997298
You will need to explicity include each file. I would suggest making a master includes file in /webroot/includes that includes all the files in the folder. You will then need to include that master include file on every page that needs it within your website.

Although this may seem like a pain, it is a commonly accepted practice and a much better idea than trying to create a function to loop through the folder and include all the files.
0
Independent Software Vendors: 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 6

Expert Comment

by:inviser
ID: 16997309
Again, remember, "<!--#include virtual=""/includes/" & File.Name & """-->" will not work because include statements are run before the page is even executed. So in the statement above, when the include is run, the value of File.Name will not be know until later. All include statements must be with literal paths, no variables.
0
 
LVL 25

Author Comment

by:kevp75
ID: 16997321
that's what I've already done.  I've gone and seperated out the area specific functions into their own include files, and then included them in a main include file (which is included on every page)

I would like to simplify this, as I may need to add more include files, (in my laziness) I don't want to have to go and add in <!--#include...blah blah blah, everytime I add a file to that folder.

what's the difference between using file/virtual include over server.execute?
0
 
LVL 6

Expert Comment

by:inviser
ID: 16997353
>> I would like to simplify this, as I may need to add more include files, (in my laziness)

I understand how you feel, but you should stick to manually adding the files each time. Any clever workaround would likely be a security breech or very inefficient.

file/virtual include is a preprocessor statement that simple pieces asp pages together into one before the execution of the asp pages as a whole

server.execute is a runtime command that will execute another asp script independently of the page that called the execution. Any output caused by the server.execute command will be included in the calling page's output, but no communication in terms of ASP code takes place and each execution is strictly independent of the other.
0
 
LVL 25

Author Comment

by:kevp75
ID: 16997391
thanks inviser
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

879 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