Solved

File Include Loop?

Posted on 2006-06-27
7
199 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
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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Specific format 21 198
Element alignment and word wrapping 9 69
age from date of birth 4 42
One field not displaying content (ASP Classic) 8 25
Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

777 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