View Full Version : Question regarding listing all files in a directory "sticky" above...
AshleyQuick
06-03-2005, 06:21 AM
In the following thread, mhtml's script is ALMOST ideal. Can someone show a way to hide this particular file and show eveything else?
http://www.codingforums.com/showthread.php?p=45564
Thanks,
Ash
Morgoth
06-03-2005, 06:55 AM
Can someone show a way to hide this particular file and show eveything else?
What file?
If File.name <> "this one" Then
'Show File
End If
AshleyQuick
06-03-2005, 06:03 PM
What file?
MHTML's file. I named his file index.asp and placed it into the directory that I choose to display the content(s). Is there a way to hide this file (index.asp)?
oracleguy
06-03-2005, 06:19 PM
Well then just put the stuff inside the for loop inside an if statement similar to what Morgoth posted.
If file.name <> "index.asp" Then
... loop code ...
End If
AshleyQuick
06-04-2005, 07:52 PM
I'm sure the solution is obvious but I cannot seem to grasp what I need to do in order to accomplish this.
Here is the file I would like to hide in the folder entitled meetings (this file is named index.asp):
<html>
<head><title>File List</title>
</head>
<body>
<ol>
<%
Set myFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set Folder = myFileSys.GetFolder(Server.MapPath("/meetings"))
for each file in Folder.Files
FileName = Left(file.name, (Len(file.name) - 4)) 'drop the extension
FileSize = cint(file.size / 1024) 'convert into kilobytes and drop the decimal
Response.Write("<li><a href='/" & file.name & "'>" & FileName & "</a> - " & FileSize & " K<br>" & chr(13))
next
Set myFileSys = nothing
%>
</ol>
</body>
</html>
oracleguy
06-04-2005, 08:35 PM
<html>
<head><title>File List</title>
</head>
<body>
<ol>
<%
Set myFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set Folder = myFileSys.GetFolder(Server.MapPath("/meetings"))
for each file in Folder.Files
If Not file.name = "index.asp" Then
FileName = Left(file.name, (Len(file.name) - 4)) 'drop the extension
FileSize = cint(file.size / 1024) 'convert into kilobytes and drop the decimal
Response.Write("<li><a href='/" & file.name & "'>" & FileName & "</a> - " & FileSize & " K<br>" & chr(13))
End If
next
Set myFileSys = nothing
%>
</ol>
</body>
</html>
This should do what you want.
Morgoth
06-04-2005, 08:43 PM
Edit: I guess oracleguy beat me to it as I was coding ;)
We have given you the answer twice now.
And your extension removal code doesn't remove extensions that are larger than 3 character long (.htm, .html)
So I added a different method, however; This new code does not like extensionless files. (Can be fixed by adding an If statement.)
<html>
<head>
<title>File List</title>
</head>
<body>
<ol>
<%
Set myFileSys = Server.CreateObject("Scripting.FileSystemObject")
Set Folder = myFileSys.GetFolder(Server.MapPath("/meetings"))
For Each File In Folder.Files
FileName = Left(File.Name, InStrRev(File.Name, ".") - 1) 'Drop extension after last period(".")
If FileName <> "index" Then
FileSize = CInt(File.Size / 1024) 'convert into kilobytes and drop the decimal
Response.Write("<li><a href='/" & File.Name & "'>" & FileName & "</a> - " & FileSize & " K<br>" & Chr(13))
End If
Next
Set myFileSys = Nothing
%>
</ol>
</body>
</html>
AshleyQuick
06-05-2005, 12:57 AM
I can see how this works now. Thanks for the help!
Ash
AshleyQuick
06-06-2005, 06:10 PM
How can this be modified so that the file extension IS shown?
Ash
Morgoth
06-06-2005, 09:09 PM
All you have to do is take the File.Name and Grab everything after the last period.
It's not hard to do.
AshleyQuick
06-07-2005, 06:08 AM
It's not hard to do.
That's easy for you to say. :)
Seriously though...I've reached an impasse. Could someone assist further?
Ash
Morgoth
06-07-2005, 07:10 PM
Common!
I gave you the code!
All you have to do is change one function name!
Fine, you twisted my arm.
File.Name = "HAPPY.ASP"
Code I gave you:
FileName = Left(File.Name, InStrRev(File.Name, ".") - 1) 'Drop extension after last period(".")
Results: FileName = "HAPPY"
Get extension code:
FileExt = Right(File.Name, InStrRev(File.Name, ".") - 1)'Drop file name before last period(".")
Results: FileExt = ".ASP"
:eek: It's so simple! :p
If you don't want to see the period when you write the extension then all you have to do is use this code:
FileExt = Right(File.Name, InStrRev(File.Name, ".") - 2)'Drop file name before last period(".")
Results: FileExt = "ASP"
Have a good day, AshleyQuick. :thumbsup:
Mhtml
06-20-2005, 04:36 PM
And your extension removal code doesn't remove extensions that are larger than 3 character long (.htm, .html)
My fault :rolleyes:, I have no idea what I was thinking. Fun times, back in the good ole days... my life moves so fast, seems like half a life time ago when I used to hang on every word of advice Whammy gave me lol...yet half you old guys have been coding for longer than I've been alive, still I have a long way to go. On the plus side, I've nearly finished my Linux distro :cool:.
Morgoth
06-20-2005, 08:47 PM
How is it your fault?
And I have no clue where Whammy went, do you? He helped me learn ASP so much, he is why I am still learning it.
oracleguy
06-21-2005, 12:30 AM
How is it your fault?
And I have no clue where Whammy went, do you? He helped me learn ASP so much, he is why I am still learning it.
I was wondering that myself, I think I might have him on my MSN but that was a long while ago, I'll have to check though when I go home.
Mhtml
06-21-2005, 06:18 AM
Well the initial code was mine. And I had his MSN but he was nearly never on, granted that was a very long time ago.
Morgoth
06-21-2005, 06:28 AM
I have MSN too.
Add me.
l4gmoralex :eek: hotmail :cool: com
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.