Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

File Include Loop?

Posted on 2006-06-27
7
Medium Priority
?
204 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: 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

Technology Partners: 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!

Question has a verified solution.

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

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
The viewer will learn how to dynamically set the form action using jQuery.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

721 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