Solved

File Include Loop?

Posted on 2006-06-27
7
197 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 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 6

Expert Comment

by:inviser
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Comment Utility
thanks inviser
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

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

16 Experts available now in Live!

Get 1:1 Help Now