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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Who can help me get a bug out of this script 3

Status
Not open for further replies.

Nogi

Technical User
Dec 10, 2004
132
BE
I'm not a script-writer at all, but found this script on the net, that should do exactly what i was searching for:

What it does is showing the files inside a particular folder, as a link (or that's at least, that's what was said).

However, i can't seem to get it to work since i keep on receiving an "expected statement" error.

I hope somebody can help me with this.

This is the code:

<%Option Explicit Const IISFOLDER = "/Partitions/Joucomatic"%>
<%
Dim fso, folder, File, Files, sFileDetails
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(IISFOLDER)
Set Files = folder.Files
For Each File in Files
'--Only show files with constant file extensions
sFileDetails = "<b>File Name: " & File.name & "</b><br>" & _
"Date Created: " & File.DateCreated & "<br>" & _
"Date Date Last Accessed: " & File.DateLastAccessed & "<br>" & _
"Last Modified Date: " & File.DateLastModified & "<br>" & _
"Type: " & File.Type & "<br>" & _ "Path: " & File.Path & "<br>" & _
"Time From Creation: " & DateDiff("n",File.DateCreated,Now) & "minutes" & "<br>" & _
"Time From Modification: " & DateDiff("n",File.DateLastModified,Now) & " minutes" & "<br>" & _
"Time From Access: " & DateDiff("n",File.DateLastAccessed,Now) & " minutes" & "<hr>"
Response.Write sFileDetails
Next
Set folder = Nothing
Set fso = Nothing
%>
</body>
</html>

Thanks in advance for your help.
 
I will try :)

you need to change this line:

Set folder = fso.GetFolder(IISFOLDER)

you need to set the correct path to your folder...something like this...

Set folder = fso.GetFolder("c:/myfolder")

or

Set folder = fso.GetFolder(server.mappath("/"))

-DNG

 
Hey thanks for your fast reply DotNetGnat.

I've changed the lign as you said into:

Set folder = fso.GetFolder(server.mappath("/partitions/Joucomatic"))

However, i get a new error now when trying to open the asp page:

Quote:

The script reported following error: Expected statement (error number 0x800A0400 hex)

In file /Partitions/new_page_2.asp

on line 1, position 0 :


Option Explicit Const IISFOLDER = "/Partitions/Joucomatic"

Unquote.

It seems my first line of code is wrong somehow.
 
ok, i tried it, but again i get this error:

Error while executing / parsing the ASP page
The script reported following error: Expected statement (error number 0x800A0400 hex)

In file /Partitions/new_page_2.asp

on line 2, position 0 :


Option Explicit

Frustrating hah?
 
Let const be literal, else make it a variable.
>[tt]Const IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")[/tt]
[tt]dim IISFOLDER
IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")[/tt]

 
ok, now my script looks like this:

<html>
<head>
<title>New Page 4</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
</head>

<body>

<%
Const IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")
dim IISFOLDER
IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")
Dim fso, folder, File, Files, sFileDetails
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(server.mappath("/partitions/Joucomatic"))
Set Files = folder.Files
For Each File in Files
'--Only show files with constant file extensions
sFileDetails = "<b>File Name: " & File.name & "</b><br>" & _
"Date Created: " & File.DateCreated & "<br>" & _
"Date Date Last Accessed: " & File.DateLastAccessed & "<br>" & _
"Last Modified Date: " & File.DateLastModified & "<br>" & _
"Type: " & File.Type & "<br>" & _ "Path: " & File.Path & "<br>" & _
"Time From Creation: " & DateDiff("n",File.DateCreated,Now) & "minutes" & "<br>" & _
"Time From Modification: " & DateDiff("n",File.DateLastModified,Now) & " minutes" & "<br>" & _
"Time From Access: " & DateDiff("n",File.DateLastAccessed,Now) & " minutes" & "<hr>"
Response.Write sFileDetails
Next
Set folder = Nothing
Set fso = Nothing
%>
</body>
</html>

And the error i get is:

Error while executing / parsing the ASP page
The script reported following error: Expected literal constant (error number 0x800A0415 hex)

In file /Partitions/new_page_2.asp
on line 2, position 59 :
Const IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")

Maybe i did something wrong?
 
Hey thanks for the work and effords you all put into helping me out.

Trying to drop that line causes the following error Tony:

Error while executing / parsing the ASP page
The script reported following error: Invalid character (error number 0x800A0408 hex)

In file /Partitions/new_page_2.asp

on line 14, position 34 :


"Type: " & File.Type & "<br>" & _ "Path: " & File.Path & "<br>" & _

 
you need to drop that line suggested by Tony and change this line:

Set folder = fso.GetFolder(server.mappath("/partitions/Joucomatic"))

TO

Set folder = fso.GetFolder(IISFOLDER)

-DNG
 
I tried what you advised DotNetGnat, but the error remains the same:

Error while executing / parsing the ASP page
The script reported following error: Invalid character (error number 0x800A0408 hex)

In file /Partitions/new_page_2.asp

on line 14, position 34 :


"Type: " & File.Type & "<br>" & _ "Path: " & File.Path & "<br>" & _
 
>"Type: " & File.Type & "<br>" & _ "Path: " & File.Path & "<br>" & _
The underscore is line continuation. You must make the thing after on a new line. (Or else ltake the & _ structure out).
[tt]
"Type: " & File.Type & "<br>" & _
"Path: " & File.Path & "<br>" & _
[/tt]
 
Hey thanks for the efforts. Wel, good news is: it think it works.

Bad news is: it didn't do what i thought it would lol.

I now receive all kinds of information of the files that are in that particular folder
(date that is was created, path, last modification etc).

All i want are just the filenames of the files that are in that folder, , that acts like a link to that particular file.

Is it hard to accomplish this?
 
You write out a hyperlink to the page. Like this.
[tt]
response.write "<a href=""" & "/Partitions/Joucomatic/" & file.name & """>" & file.name & "</a><br />"
[/tt]
I would like to soft code the "/partitions/joucomatic/" but now that you hav iisfolder so defined, it is not directly available for this purpose. You just need to rearrange the way to use that variable to make that part more flexible.
 
I tried adding the code like this tsuji:

<html>
<head>
<title>New Page 4</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
</head>

<body>

<%
dim IISFOLDER
IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")
Dim fso, folder, File, Files, sFileDetails
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(IISFOLDER)
Set Files = folder.Files
For Each File in Files
'--Only show files with constant file extensions
sFileDetails = "<b>File Name: " & File.name & "</b><br>" & _
response.write "<a href=""" & "/Partitions/Joucomatic/" & file.name & """>" & file.name & "</a><br />"
Next
Set folder = Nothing
Set fso = Nothing
%>
</body>
</html>

But it had as result:

Error while executing / parsing the ASP page
The script reported following error: Expected end of statement (error number 0x800A0401 hex)

In file /Partitions/new_page_2.asp

on line 11, position 15 :

response.write "<a href=""" & "/Partitions/Joucomatic/" & file.name & """>" & file.name & "</a><br />"

I probably did this whole wrong, didn't i?
 
I now receive all kinds of information of the files that are in that particular folder
(date that is was created, path, last modification etc).

Well it looks like the reason you receive "all kinds of information" is that your code is written to display all kinds of information... Consider this FOR EACH loop where you iterate through all the files:
Code:
For Each File in Files 
sFileDetails = "<b>File Name: " & File.name & "</b><br>" & _ 
"Date Created: " & File.DateCreated & "<br>" & _ 
"Date Date Last Accessed: " & File.DateLastAccessed & "<br>" & _ 
"Last Modified Date: " & File.DateLastModified & "<br>" & _ 
"Type: " & File.Type & "<br>" & _ "Path: " & File.Path & "<br>" & _ 
"Time From Creation: " & DateDiff("n",File.DateCreated,Now) & "minutes" & "<br>" & _ 
"Time From Modification: " & DateDiff("n",File.DateLastModified,Now) & " minutes" & "<br>" & _ 
"Time From Access: " & DateDiff("n",File.DateLastAccessed,Now) & " minutes" & "<hr>" 
Response.Write sFileDetails 
Next


So if all you want are the file names, you can get rid of most of the code inside the loop:
Code:
For Each File in Files 
  sFileDetails = "<b>File Name: " & File.name & "</b><br>"
  Response.Write sFileDetails 
Next



Oh, and if you want them to be links, then add the HTML to make them into links... I'll show it written out the long way in mixed code/html but you could just as well use Response.Write:
Code:
For Each File in Files 
%>
  <b>
    File Name:
    <a href = '/Partitions/Joucomatic/<%= File.Name %>'
       <%= File.Name %>
    </a>
  </b>
  <br />
<%
Next
 
Ah sorry, you guys had moved on while I was still typing my reply...

The "expected end of statement" error looks like a problem with the quotes.... the browser parser will work just as well with the single quote character as the double quote (even if it wont validate) and that saves you from having to escape the double quotes.
 
>[tt]sFileDetails = "<b>File Name: " & File.name & "</b><br>" & _ [/tt]
Can you drop this line? (It has a line continuation.) Of if you want both.
[tt]
response.write "<b>File Name: " & File.name & "</b><br />"
response.write "<a href=""" & "/Partitions/Joucomatic/" & file.name & """>" & file.name & "</a><br />"
[/tt]
Don't know if you really like hyperlink or not as you wrote:
>that acts like a link to that particular file.
If not, you can make thing easier. Just write the first line.
 
I must probably look like a fool to you guys but uhm...
is this how my complete .asp must look like then?

<html>
<head>
<title>New Page 4</title>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
</head>

<body>

<%
dim IISFOLDER
IISFOLDER = Server.MapPath("/Partitions/Joucomatic/")
Dim fso, folder, File, Files, sFileDetails
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(IISFOLDER)
Set Files = folder.Files
For Each File in Files
For Each File in Files
%>
<b>
File Name:
<a href = '/Partitions/Joucomatic/<%= File.Name %>'
<%= File.Name %>
</a>
</b>
<br />
<%
Next
Set folder = Nothing
Set fso = Nothing
%>
</body>
</html>

Again, sorry for my less of knowledge on this subject, and thanks for your patience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top