Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

number of files in a web folder

Status
Not open for further replies.

NewbiDoobie

Technical User
Jul 25, 2005
63
US
I have a site uploaded to a server. Within this site I have a folder which contains between 5 to 10 separate web pages which are loaded into an inline frame at random.

What I am trying to do is:
A: get the count of the number of files in the web folder
B: generate a random number based on the count of files
C: display that file into the iframe on my page

Since I am not sure of the full directory of the server it is on, is it possible to get this in relation to the web pages I am loading?

I am trying something like this, but I keep getting errors:

    Dim oFSO
    Dim oFolder   
    Dim FileCount
Set oFSO = server.CreateObject("Scripting.FileSystemObject")'   
set oFolder = oFSO.GetFolder("Application("WebRoot")" & "/rotation"
    Randomize
     filecount = cint(oFolder.Files.Count) * Rnd ) + 1'
 
First of all, try this to get the path of the folder...
Code:
set oFolder =  oFSO.GetFolder(Application("WebRoot") & "/rotation"
assuming that [red]Application("WebRoot") [/red] is an absolute path. I've removed the quotes you had around your Application variable.

If it isn't an absolute path then try using...
Code:
set oFolder =  oFSO.GetFolder(Server.MapPath("/rotation"))

Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
That came back with an error:
Microsoft VBScript compilation , (0x800A0408), Invalid character, /Default.asp, line 109, column 13, GET , /Default.asp,

Here is what I have for the code now:

Dim oFSO
Dim oFolder
Dim FileCount

Set oFSO = server.CreateObject"scripting.FileSystemObject")

set oFolder =  oFSO.GetFolder(Server.MapPath("/rotation"))
Randomize  
filecount = cint(oFolder.Files.Count) * Rnd ) + 1
 
oops i missed a [red])[/red]
Code:
set oFolder =  oFSO.GetFolder(Application("WebRoot") & "/rotation"[red])[/red]
What is actually in Application("WebRoot")?

you also have a missing [red]([/red]
Code:
Set oFSO = server.CreateObject[red]([/red]"scripting.FileSystemObject")


Tony

Spirax-Sarco - steam traps control valves heat exchangers
Sun Villa - Luxury Florida accommodation
 
alright I get the count of the files, but it will not generate the random number. Can I pass a vbscript variable to a javascript funtion?

Dim oFSO
Dim oFolder
Dim FileCount
dim count1

Set oFSO = server.CreateObject("scripting.FileSystemObject")

Set oFolder = oFSO.GetFolder(Server.MapPath("/rotation"))

count1 = cint(oFolder.Files.Count)
Response.Write count1
Randomize 

filecount = cint(cint(oFolder.Files.Count) * Rnd ) + 1
Response.Write filecount

if I comment out the random number section I get the count diplayed, however the last section is throwing errors.

Randomize
filecount = cint(cint(oFolder.Files.Count) * Rnd ) + 1
Response.Write filecount
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top