Click to See Complete Forum and Search --> : returning the sub-level of any given file


antonielloj
05-01-2003, 09:08 AM
hey all. is there any way that i can write a function in javascript that i attach to every html file that can determine how many levels deep the file is within the site? and then return a number based on its sub-level. i.e. if it is in the root directory, it returns 0, and if it is two levels deep, it returns 2, etc etc...?

any help would be great. thanks.
cheers

khalidali63
05-01-2003, 09:10 AM
aaannhh..:D

Care to elaborate a bit more please..

antonielloj
05-01-2003, 03:31 PM
surely. :)

i want to write a script that determines how many folders/levels beneath the root directory a file is. for example, suppose the architecture of my site looks like this:

root >
  index.html
  folder1 >
    a.html
    b.html
    c.html
    folder2 >
      d.html
      e.html
  folder3 >
    f.html
    g.html

i want to attach a script in the head of each html page that will return a number based on how its level relative to the root. so:
when index.html loads, the script is called and returns 0.
when b.html loads, the script is called and returns 1.
when e.html loads, the script is called and returns 2.
when g.html loads, the script is called and returns 1.
etc etc etc.

is this possible?

i was thinking of possible ways to do this, perhaps by creating a blank file called 'anchor.txt' and storing it at the root level, and then have the script scan the file's current directory for 'anchor.txt', and if it cant find it, then jump to the parent folder, inc a counter, re-scan, etc... but i dont know how to do this with javascript, or if it is even possible at all... any solution would be greatly appreciated, however crude it might be.

thanks so much.

khalidali63
05-01-2003, 03:36 PM
Nope...not with JavaScript only,however,there may be some other ways ,like,using java or some other server side lang to get this done.