Not sure if this is the spot to ask but I need some help with a script I
hijacked and put to my own use in an .ASP page

any ways I am using the FilesystemObjects to get a directory and file
listing and generating a web page of that listing, but I need to filter out
files with the SYSTEM tag, so it wont show files I dont want it to, Below is
my full code for the ASP page, I have Commented where I need to change the
listing structure, if anyone can help me filter these out I would be
greatfull!!!


--- Begin code ---
<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
On Error Resume Next

' this section is optional - it just denies anonymous access
If Request.ServerVariables("LOGON_USER")="" Then
Response.Status = "401 Access Denied"
End If

' declare variables
Dim objFSO, objFolder
Dim objCollection, objItem

Dim strPhysicalPath, strTitle, strServerName
Dim strPath, strTemp
Dim strName, strFile, strExt, strAttr
Dim intSizeB, intSizeK, intAttr, dtmDate

' declare constants
Const vbReadOnly = 1
Const vbHidden = 2
Const vbSystem = 4
Const vbVolume = 8
Const vbDirectory = 16
Const vbArchive = 32
Const vbAlias = 64
Const vbCompressed = 128

' don't cache the page
Response.AddHeader "Pragma", "No-Cache"
Response.CacheControl = "Private"

' get the current folder URL path
strTemp = Mid(Request.ServerVariables("URL"),2)
strPath = ""

Do While Instr(strTemp,"/")
strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
strTemp = Mid(strTemp,Instr(strTemp,"/")+1)
Loop

strPath = "/" & strPath

' build the page title
strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
strTitle = "Contents of the " & strPath & " folder"

' create the file system objects
strPhysicalPath = Server.MapPath(strPath)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPhysicalPath)
%>

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title></title>
</head>

<body text="#C0C0C0" bgcolor="#000000">

<div align="center">
<table border="0" width="80%" id="table1">
<tr>
<td align="center">Some web page Info here<p align="right"><b><font
size="4">And here</font></b></td>
</tr>
</table>
</div>
<p align="center">
<img border="0" src="Folder.jpg">
</p>

<p align="center"><a href="../">Back</a></p>


<html>
<body>

<div align="center"><center>
<table width="100%" border="0" cellspacing="1" cellpadding="2">

<%
''''''''''''''''''''''''''''''''''''''''
' output the folder list
''''''''''''''''''''''''''''''''''''''''

Set objCollection = objFolder.SubFolders

For Each objItem in objCollection
strName = objItem.Name
strAttr = MakeAttr(objItem.Attributes)
dtmDate = CDate(objItem.DateLastModified)
%>
<% Next %>

<%
''''''''''''''''''''''''''''''''''''''''
' output the file list
''''''''''''''''''''''''''''''''''''''''

Set objCollection = objFolder.Files

For Each objItem in objCollection
strName = objItem.Name
strFile = Server.HTMLEncode(Lcase(strName))

intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1

strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Instr(strName,".") Then strExt =
Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
dtmDate = CDate(objItem.DateLastModified)
%>
' This is where I am listing the Files in my webpage, but it lists all
files, and I need to block the listing of system Files'
<tr>
<td align="left">A<%=strFile%></a></td>
<td align="right"> </td>
<td align="right">
<p align="left"><%=intSizeK%>K</td>
</tr>
<% Next %>

</table>
</center></div>

</body>
</html>
<%
Set objFSO = Nothing
Set objFolder = Nothing

' this adds the IIf() function to VBScript
Function IIf(i,j,k)
If i Then IIf = j Else IIf = k
End Function

' this function creates a string from the file atttributes
Function MakeAttr(intAttr)
MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
End Function
%>

Re: Help with VB in an ASP script by Alex

Alex
Mon May 12 14:58:20 CDT 2008

The file attributes is a bit mask setting, which means that boolean
operations can tell you whether or not the system flag is set. Hereâ??s what
you do.

When you get to the code chunk
Set objCollection = objFolder.Files

For Each objItem in objCollection

each objItem is a file. You can test objItem.Attributes to see if it
contains the value 4 for a System file, with an expression like this:
(objItem.Attributes and 4)
This returns 0 if the file does NOT have the system attribute set, and a
nonzero value if it does. You need to force this to a simple true-false
value, like this:
CBool(objItem.Attributes and 4)
The reason is that once it is true or false, using Not on it gives you a
true if the file wasn't a system file but false if it was a system file. YOu
just wrap up the output inside an if-then statement testing the attribute,
like this

For Each objItem in objCollection
if not( CBool(objItem.Attributes and 4) ) then
' do output statements here, since not a system file
end if
next




"EQNish" <EQNish@discussions.microsoft.com> wrote in message
news:64C5D003-690E-472C-9274-0BF7B683137C@microsoft.com...
> Not sure if this is the spot to ask but I need some help with a script I
> hijacked and put to my own use in an .ASP page
>
> any ways I am using the FilesystemObjects to get a directory and file
> listing and generating a web page of that listing, but I need to filter
> out
> files with the SYSTEM tag, so it wont show files I dont want it to, Below
> is
> my full code for the ASP page, I have Commented where I need to change the
> listing structure, if anyone can help me filter these out I would be
> greatfull!!!
>
>
> --- Begin code ---
> <%@LANGUAGE="VBSCRIPT"%>
> <%
> Option Explicit
> On Error Resume Next
>
> ' this section is optional - it just denies anonymous access
> If Request.ServerVariables("LOGON_USER")="" Then
> Response.Status = "401 Access Denied"
> End If
>
> ' declare variables
> Dim objFSO, objFolder
> Dim objCollection, objItem
>
> Dim strPhysicalPath, strTitle, strServerName
> Dim strPath, strTemp
> Dim strName, strFile, strExt, strAttr
> Dim intSizeB, intSizeK, intAttr, dtmDate
>
> ' declare constants
> Const vbReadOnly = 1
> Const vbHidden = 2
> Const vbSystem = 4
> Const vbVolume = 8
> Const vbDirectory = 16
> Const vbArchive = 32
> Const vbAlias = 64
> Const vbCompressed = 128
>
> ' don't cache the page
> Response.AddHeader "Pragma", "No-Cache"
> Response.CacheControl = "Private"
>
> ' get the current folder URL path
> strTemp = Mid(Request.ServerVariables("URL"),2)
> strPath = ""
>
> Do While Instr(strTemp,"/")
> strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
> strTemp = Mid(strTemp,Instr(strTemp,"/")+1)
> Loop
>
> strPath = "/" & strPath
>
> ' build the page title
> strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
> strTitle = "Contents of the " & strPath & " folder"
>
> ' create the file system objects
> strPhysicalPath = Server.MapPath(strPath)
> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> Set objFolder = objFSO.GetFolder(strPhysicalPath)
> %>
>
> <html>
>
> <head>
> <meta http-equiv="Content-Language" content="en-us">
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title></title>
> </head>
>
> <body text="#C0C0C0" bgcolor="#000000">
>
> <div align="center">
> <table border="0" width="80%" id="table1">
> <tr>
> <td align="center">Some web page Info here<p align="right"><b><font
> size="4">And here</font></b></td>
> </tr>
> </table>
> </div>
> <p align="center">
> <img border="0" src="Folder.jpg">
> </p>
>
> <p align="center"><a href="../">Back</a></p>
>
>
> <html>
> <body>
>
> <div align="center"><center>
> <table width="100%" border="0" cellspacing="1" cellpadding="2">
>
> <%
> ''''''''''''''''''''''''''''''''''''''''
> ' output the folder list
> ''''''''''''''''''''''''''''''''''''''''
>
> Set objCollection = objFolder.SubFolders
>
> For Each objItem in objCollection
> strName = objItem.Name
> strAttr = MakeAttr(objItem.Attributes)
> dtmDate = CDate(objItem.DateLastModified)
> %>
> <% Next %>
>
> <%
> ''''''''''''''''''''''''''''''''''''''''
> ' output the file list
> ''''''''''''''''''''''''''''''''''''''''
>
> Set objCollection = objFolder.Files
>
> For Each objItem in objCollection
> strName = objItem.Name
> strFile = Server.HTMLEncode(Lcase(strName))
>
> intSizeB = objItem.Size
> intSizeK = Int((intSizeB/1024) + .5)
> If intSizeK = 0 Then intSizeK = 1
>
> strAttr = MakeAttr(objItem.Attributes)
> strName = Ucase(objItem.ShortName)
> If Instr(strName,".") Then strExt =
> Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
> dtmDate = CDate(objItem.DateLastModified)
> %>
> ' This is where I am listing the Files in my webpage, but it lists all
> files, and I need to block the listing of system Files'
> <tr>
> <td align="left">A<%=strFile%></a></td>
> <td align="right"> </td>
> <td align="right">
> <p align="left"><%=intSizeK%>K</td>
> </tr>
> <% Next %>
>
> </table>
> </center></div>
>
> </body>
> </html>
> <%
> Set objFSO = Nothing
> Set objFolder = Nothing
>
> ' this adds the IIf() function to VBScript
> Function IIf(i,j,k)
> If i Then IIf = j Else IIf = k
> End Function
>
> ' this function creates a string from the file atttributes
> Function MakeAttr(intAttr)
> MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
> MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
> MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
> MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
> End Function
> %>


Re: Help with VB in an ASP script by EQNish

EQNish
Mon May 12 15:49:17 CDT 2008

Alex thanks for your help,

I ahve tried to impliment what you said, but I can't get it to parse out the
unwanted files! I think it has something to do with how I am writing the
data to the web page:

--- code begin ---
<%
''''''''''''''''''''''''''''''''''''''''
' output the file list
''''''''''''''''''''''''''''''''''''''''

Set objCollection = objFolder.Files

For Each objItem in objCollection
strName = objItem.Name
strFile = Server.HTMLEncode(strName)
intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Instr(strName,".") Then strExt =
Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
dtmDate = CDate(objItem.DateLastModified)
%>
'**** This is where the File data is writing to the HTML page, by using
simple Strings and a Loop started above *** You can see creat a string for
attributes called strAttr, for which the origanl script was writing the
attribute to the html. I thought I could use that string to do my check, and
remove that bit of data, however all I end up with is a bad page
<tr>
<td align="left"><%=strFile%></a></td>
<td align="right"> </td>
<td align="right">
<p align="left"><%=intSizeK%>K</td>
</tr>

<% Next %>

</table>



"Alex K. Angelopoulos" wrote:

> The file attributes is a bit mask setting, which means that boolean
> operations can tell you whether or not the system flag is set. Hereâ??s what
> you do.
>
> When you get to the code chunk
> Set objCollection = objFolder.Files
>
> For Each objItem in objCollection
>
> each objItem is a file. You can test objItem.Attributes to see if it
> contains the value 4 for a System file, with an expression like this:
> (objItem.Attributes and 4)
> This returns 0 if the file does NOT have the system attribute set, and a
> nonzero value if it does. You need to force this to a simple true-false
> value, like this:
> CBool(objItem.Attributes and 4)
> The reason is that once it is true or false, using Not on it gives you a
> true if the file wasn't a system file but false if it was a system file. YOu
> just wrap up the output inside an if-then statement testing the attribute,
> like this
>
> For Each objItem in objCollection
> if not( CBool(objItem.Attributes and 4) ) then
> ' do output statements here, since not a system file
> end if
> next
>
>
>
>
> "EQNish" <EQNish@discussions.microsoft.com> wrote in message
> news:64C5D003-690E-472C-9274-0BF7B683137C@microsoft.com...
> > Not sure if this is the spot to ask but I need some help with a script I
> > hijacked and put to my own use in an .ASP page
> >
> > any ways I am using the FilesystemObjects to get a directory and file
> > listing and generating a web page of that listing, but I need to filter
> > out
> > files with the SYSTEM tag, so it wont show files I dont want it to, Below
> > is
> > my full code for the ASP page, I have Commented where I need to change the
> > listing structure, if anyone can help me filter these out I would be
> > greatfull!!!
> >
> >
> > --- Begin code ---
> > <%@LANGUAGE="VBSCRIPT"%>
> > <%
> > Option Explicit
> > On Error Resume Next
> >
> > ' this section is optional - it just denies anonymous access
> > If Request.ServerVariables("LOGON_USER")="" Then
> > Response.Status = "401 Access Denied"
> > End If
> >
> > ' declare variables
> > Dim objFSO, objFolder
> > Dim objCollection, objItem
> >
> > Dim strPhysicalPath, strTitle, strServerName
> > Dim strPath, strTemp
> > Dim strName, strFile, strExt, strAttr
> > Dim intSizeB, intSizeK, intAttr, dtmDate
> >
> > ' declare constants
> > Const vbReadOnly = 1
> > Const vbHidden = 2
> > Const vbSystem = 4
> > Const vbVolume = 8
> > Const vbDirectory = 16
> > Const vbArchive = 32
> > Const vbAlias = 64
> > Const vbCompressed = 128
> >
> > ' don't cache the page
> > Response.AddHeader "Pragma", "No-Cache"
> > Response.CacheControl = "Private"
> >
> > ' get the current folder URL path
> > strTemp = Mid(Request.ServerVariables("URL"),2)
> > strPath = ""
> >
> > Do While Instr(strTemp,"/")
> > strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
> > strTemp = Mid(strTemp,Instr(strTemp,"/")+1)
> > Loop
> >
> > strPath = "/" & strPath
> >
> > ' build the page title
> > strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
> > strTitle = "Contents of the " & strPath & " folder"
> >
> > ' create the file system objects
> > strPhysicalPath = Server.MapPath(strPath)
> > Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> > Set objFolder = objFSO.GetFolder(strPhysicalPath)
> > %>
> >
> > <html>
> >
> > <head>
> > <meta http-equiv="Content-Language" content="en-us">
> > <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> > <title></title>
> > </head>
> >
> > <body text="#C0C0C0" bgcolor="#000000">
> >
> > <div align="center">
> > <table border="0" width="80%" id="table1">
> > <tr>
> > <td align="center">Some web page Info here<p align="right"><b><font
> > size="4">And here</font></b></td>
> > </tr>
> > </table>
> > </div>
> > <p align="center">
> > <img border="0" src="Folder.jpg">
> > </p>
> >
> > <p align="center"><a href="../">Back</a></p>
> >
> >
> > <html>
> > <body>
> >
> > <div align="center"><center>
> > <table width="100%" border="0" cellspacing="1" cellpadding="2">
> >
> > <%
> > ''''''''''''''''''''''''''''''''''''''''
> > ' output the folder list
> > ''''''''''''''''''''''''''''''''''''''''
> >
> > Set objCollection = objFolder.SubFolders
> >
> > For Each objItem in objCollection
> > strName = objItem.Name
> > strAttr = MakeAttr(objItem.Attributes)
> > dtmDate = CDate(objItem.DateLastModified)
> > %>
> > <% Next %>
> >
> > <%
> > ''''''''''''''''''''''''''''''''''''''''
> > ' output the file list
> > ''''''''''''''''''''''''''''''''''''''''
> >
> > Set objCollection = objFolder.Files
> >
> > For Each objItem in objCollection
> > strName = objItem.Name
> > strFile = Server.HTMLEncode(Lcase(strName))
> >
> > intSizeB = objItem.Size
> > intSizeK = Int((intSizeB/1024) + .5)
> > If intSizeK = 0 Then intSizeK = 1
> >
> > strAttr = MakeAttr(objItem.Attributes)
> > strName = Ucase(objItem.ShortName)
> > If Instr(strName,".") Then strExt =
> > Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
> > dtmDate = CDate(objItem.DateLastModified)
> > %>
> > ' This is where I am listing the Files in my webpage, but it lists all
> > files, and I need to block the listing of system Files'
> > <tr>
> > <td align="left">A<%=strFile%></a></td>
> > <td align="right"> </td>
> > <td align="right">
> > <p align="left"><%=intSizeK%>K</td>
> > </tr>
> > <% Next %>
> >
> > </table>
> > </center></div>
> >
> > </body>
> > </html>
> > <%
> > Set objFSO = Nothing
> > Set objFolder = Nothing
> >
> > ' this adds the IIf() function to VBScript
> > Function IIf(i,j,k)
> > If i Then IIf = j Else IIf = k
> > End Function
> >
> > ' this function creates a string from the file atttributes
> > Function MakeAttr(intAttr)
> > MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
> > MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
> > MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
> > MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
> > End Function
> > %>
>
>

Re: Help with VB in an ASP script by Bob

Bob
Mon May 12 17:35:57 CDT 2008

EQNish wrote:
> Not sure if this is the spot to ask but I need some help with a
> script I hijacked and put to my own use in an .ASP page
>

Please don't multipost. I almost wasted a lot of time duplicating what
Alex wrote. If I had gone to the trouble, I can tell you that I would
not be very inclined to answer future posts from you.
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.



Re: Help with VB in an ASP script by Alex

Alex
Mon May 12 19:10:10 CDT 2008

Are you sure you're doing that? The code you posted doesn't include the
if-then to filter out the system files.

"EQNish" <EQNish@discussions.microsoft.com> wrote in message
news:09B444C9-F668-42D7-86D6-12B631E0EBF9@microsoft.com...
> Alex thanks for your help,
>
> I ahve tried to impliment what you said, but I can't get it to parse out
> the
> unwanted files! I think it has something to do with how I am writing the
> data to the web page:
>
> --- code begin ---
> <%
> ''''''''''''''''''''''''''''''''''''''''
> ' output the file list
> ''''''''''''''''''''''''''''''''''''''''
>
> Set objCollection = objFolder.Files
>
> For Each objItem in objCollection
> strName = objItem.Name
> strFile = Server.HTMLEncode(strName)
> intSizeB = objItem.Size
> intSizeK = Int((intSizeB/1024) + .5)
> If intSizeK = 0 Then intSizeK = 1
> strAttr = MakeAttr(objItem.Attributes)
> strName = Ucase(objItem.ShortName)
> If Instr(strName,".") Then strExt =
> Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
> dtmDate = CDate(objItem.DateLastModified)
> %>
> '**** This is where the File data is writing to the HTML page, by using
> simple Strings and a Loop started above *** You can see creat a string
> for
> attributes called strAttr, for which the origanl script was writing the
> attribute to the html. I thought I could use that string to do my check,
> and
> remove that bit of data, however all I end up with is a bad page
> <tr>
> <td align="left"><%=strFile%></a></td>
> <td align="right"> </td>
> <td align="right">
> <p align="left"><%=intSizeK%>K</td>
> </tr>
>
> <% Next %>
>
> </table>
>
>
>
> "Alex K. Angelopoulos" wrote:
>
>> The file attributes is a bit mask setting, which means that boolean
>> operations can tell you whether or not the system flag is set. Hereâ??s
>> what
>> you do.
>>
>> When you get to the code chunk
>> Set objCollection = objFolder.Files
>>
>> For Each objItem in objCollection
>>
>> each objItem is a file. You can test objItem.Attributes to see if it
>> contains the value 4 for a System file, with an expression like this:
>> (objItem.Attributes and 4)
>> This returns 0 if the file does NOT have the system attribute set, and a
>> nonzero value if it does. You need to force this to a simple true-false
>> value, like this:
>> CBool(objItem.Attributes and 4)
>> The reason is that once it is true or false, using Not on it gives you a
>> true if the file wasn't a system file but false if it was a system file.
>> YOu
>> just wrap up the output inside an if-then statement testing the
>> attribute,
>> like this
>>
>> For Each objItem in objCollection
>> if not( CBool(objItem.Attributes and 4) ) then
>> ' do output statements here, since not a system file
>> end if
>> next
>>
>>
>>
>>
>> "EQNish" <EQNish@discussions.microsoft.com> wrote in message
>> news:64C5D003-690E-472C-9274-0BF7B683137C@microsoft.com...
>> > Not sure if this is the spot to ask but I need some help with a script
>> > I
>> > hijacked and put to my own use in an .ASP page
>> >
>> > any ways I am using the FilesystemObjects to get a directory and file
>> > listing and generating a web page of that listing, but I need to filter
>> > out
>> > files with the SYSTEM tag, so it wont show files I dont want it to,
>> > Below
>> > is
>> > my full code for the ASP page, I have Commented where I need to change
>> > the
>> > listing structure, if anyone can help me filter these out I would be
>> > greatfull!!!
>> >
>> >
>> > --- Begin code ---
>> > <%@LANGUAGE="VBSCRIPT"%>
>> > <%
>> > Option Explicit
>> > On Error Resume Next
>> >
>> > ' this section is optional - it just denies anonymous access
>> > If Request.ServerVariables("LOGON_USER")="" Then
>> > Response.Status = "401 Access Denied"
>> > End If
>> >
>> > ' declare variables
>> > Dim objFSO, objFolder
>> > Dim objCollection, objItem
>> >
>> > Dim strPhysicalPath, strTitle, strServerName
>> > Dim strPath, strTemp
>> > Dim strName, strFile, strExt, strAttr
>> > Dim intSizeB, intSizeK, intAttr, dtmDate
>> >
>> > ' declare constants
>> > Const vbReadOnly = 1
>> > Const vbHidden = 2
>> > Const vbSystem = 4
>> > Const vbVolume = 8
>> > Const vbDirectory = 16
>> > Const vbArchive = 32
>> > Const vbAlias = 64
>> > Const vbCompressed = 128
>> >
>> > ' don't cache the page
>> > Response.AddHeader "Pragma", "No-Cache"
>> > Response.CacheControl = "Private"
>> >
>> > ' get the current folder URL path
>> > strTemp = Mid(Request.ServerVariables("URL"),2)
>> > strPath = ""
>> >
>> > Do While Instr(strTemp,"/")
>> > strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
>> > strTemp = Mid(strTemp,Instr(strTemp,"/")+1)
>> > Loop
>> >
>> > strPath = "/" & strPath
>> >
>> > ' build the page title
>> > strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
>> > strTitle = "Contents of the " & strPath & " folder"
>> >
>> > ' create the file system objects
>> > strPhysicalPath = Server.MapPath(strPath)
>> > Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
>> > Set objFolder = objFSO.GetFolder(strPhysicalPath)
>> > %>
>> >
>> > <html>
>> >
>> > <head>
>> > <meta http-equiv="Content-Language" content="en-us">
>> > <meta http-equiv="Content-Type" content="text/html;
>> > charset=windows-1252">
>> > <title></title>
>> > </head>
>> >
>> > <body text="#C0C0C0" bgcolor="#000000">
>> >
>> > <div align="center">
>> > <table border="0" width="80%" id="table1">
>> > <tr>
>> > <td align="center">Some web page Info here<p align="right"><b><font
>> > size="4">And here</font></b></td>
>> > </tr>
>> > </table>
>> > </div>
>> > <p align="center">
>> > <img border="0" src="Folder.jpg">
>> > </p>
>> >
>> > <p align="center"><a href="../">Back</a></p>
>> >
>> >
>> > <html>
>> > <body>
>> >
>> > <div align="center"><center>
>> > <table width="100%" border="0" cellspacing="1" cellpadding="2">
>> >
>> > <%
>> > ''''''''''''''''''''''''''''''''''''''''
>> > ' output the folder list
>> > ''''''''''''''''''''''''''''''''''''''''
>> >
>> > Set objCollection = objFolder.SubFolders
>> >
>> > For Each objItem in objCollection
>> > strName = objItem.Name
>> > strAttr = MakeAttr(objItem.Attributes)
>> > dtmDate = CDate(objItem.DateLastModified)
>> > %>
>> > <% Next %>
>> >
>> > <%
>> > ''''''''''''''''''''''''''''''''''''''''
>> > ' output the file list
>> > ''''''''''''''''''''''''''''''''''''''''
>> >
>> > Set objCollection = objFolder.Files
>> >
>> > For Each objItem in objCollection
>> > strName = objItem.Name
>> > strFile = Server.HTMLEncode(Lcase(strName))
>> >
>> > intSizeB = objItem.Size
>> > intSizeK = Int((intSizeB/1024) + .5)
>> > If intSizeK = 0 Then intSizeK = 1
>> >
>> > strAttr = MakeAttr(objItem.Attributes)
>> > strName = Ucase(objItem.ShortName)
>> > If Instr(strName,".") Then strExt =
>> > Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
>> > dtmDate = CDate(objItem.DateLastModified)
>> > %>
>> > ' This is where I am listing the Files in my webpage, but it lists all
>> > files, and I need to block the listing of system Files'
>> > <tr>
>> > <td align="left">A<%=strFile%></a></td>
>> > <td align="right"> </td>
>> > <td align="right">
>> > <p align="left"><%=intSizeK%>K</td>
>> > </tr>
>> > <% Next %>
>> >
>> > </table>
>> > </center></div>
>> >
>> > </body>
>> > </html>
>> > <%
>> > Set objFSO = Nothing
>> > Set objFolder = Nothing
>> >
>> > ' this adds the IIf() function to VBScript
>> > Function IIf(i,j,k)
>> > If i Then IIf = j Else IIf = k
>> > End Function
>> >
>> > ' this function creates a string from the file atttributes
>> > Function MakeAttr(intAttr)
>> > MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
>> > MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
>> > MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
>> > MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
>> > End Function
>> > %>
>>
>>

Re: Help with VB in an ASP script by EQNish

EQNish
Mon May 12 21:11:02 CDT 2008

well... I have added the code like this:
''''''''''''''''''''''''''''''''''''''''
' output the file list
''''''''''''''''''''''''''''''''''''''''

Set objCollection = objFolder.Files

For Each objItem in objCollection
strName = objItem.Name
strFile = Server.HTMLEncode(strName)

intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Not ( CBool(strAttr and 4) ) then ' But right here, I'm not sure
how to remove the Data'
If Instr(strName,".") Then strExt =
Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
dtmDate = CDate(objItem.DateLastModified)

As you can see in the rest of my code the HTML part uses strings from the
VBScript to build the web page based on the file/directory structure. The <%
Next %> statement is what makes the loop, everytime I put anything like your
code in the loop fails. Also after looking at this as much as I can, I don't
think I am even using the last two lines of code as I'm not using the file
dates and I'm not 100% on what that second to last line above does. I do
know anything I do with the If then Loops blows my for - next Loop completly
out!... I'll keep digging, I'm also trying to figure a way to do allof this
with one asp file in the Root Dir, instead of one in every sub-dir!!!! but I
had to start somewhere and learn more then I know!!!



"Alex K. Angelopoulos" wrote:

> Are you sure you're doing that? The code you posted doesn't include the
> if-then to filter out the system files.
>
> "EQNish" <EQNish@discussions.microsoft.com> wrote in message
> news:09B444C9-F668-42D7-86D6-12B631E0EBF9@microsoft.com...
> > Alex thanks for your help,
> >
> > I ahve tried to impliment what you said, but I can't get it to parse out
> > the
> > unwanted files! I think it has something to do with how I am writing the
> > data to the web page:
> >
> > --- code begin ---
> > <%
> > ''''''''''''''''''''''''''''''''''''''''
> > ' output the file list
> > ''''''''''''''''''''''''''''''''''''''''
> >
> > Set objCollection = objFolder.Files
> >
> > For Each objItem in objCollection
> > strName = objItem.Name
> > strFile = Server.HTMLEncode(strName)
> > intSizeB = objItem.Size
> > intSizeK = Int((intSizeB/1024) + .5)
> > If intSizeK = 0 Then intSizeK = 1
> > strAttr = MakeAttr(objItem.Attributes)
> > strName = Ucase(objItem.ShortName)
> > If Instr(strName,".") Then strExt =
> > Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
> > dtmDate = CDate(objItem.DateLastModified)
> > %>
> > '**** This is where the File data is writing to the HTML page, by using
> > simple Strings and a Loop started above *** You can see creat a string
> > for
> > attributes called strAttr, for which the origanl script was writing the
> > attribute to the html. I thought I could use that string to do my check,
> > and
> > remove that bit of data, however all I end up with is a bad page
> > <tr>
> > <td align="left"><%=strFile%></a></td>
> > <td align="right"> </td>
> > <td align="right">
> > <p align="left"><%=intSizeK%>K</td>
> > </tr>
> >
> > <% Next %>
> >
> > </table>
> >
> >
> >
> > "Alex K. Angelopoulos" wrote:
> >
> >> The file attributes is a bit mask setting, which means that boolean
> >> operations can tell you whether or not the system flag is set. Hereâ??s
> >> what
> >> you do.
> >>
> >> When you get to the code chunk
> >> Set objCollection = objFolder.Files
> >>
> >> For Each objItem in objCollection
> >>
> >> each objItem is a file. You can test objItem.Attributes to see if it
> >> contains the value 4 for a System file, with an expression like this:
> >> (objItem.Attributes and 4)
> >> This returns 0 if the file does NOT have the system attribute set, and a
> >> nonzero value if it does. You need to force this to a simple true-false
> >> value, like this:
> >> CBool(objItem.Attributes and 4)
> >> The reason is that once it is true or false, using Not on it gives you a
> >> true if the file wasn't a system file but false if it was a system file.
> >> YOu
> >> just wrap up the output inside an if-then statement testing the
> >> attribute,
> >> like this
> >>
> >> For Each objItem in objCollection
> >> if not( CBool(objItem.Attributes and 4) ) then
> >> ' do output statements here, since not a system file
> >> end if
> >> next
> >>
> >>
> >>
> >>
> >> "EQNish" <EQNish@discussions.microsoft.com> wrote in message
> >> news:64C5D003-690E-472C-9274-0BF7B683137C@microsoft.com...
> >> > Not sure if this is the spot to ask but I need some help with a script
> >> > I
> >> > hijacked and put to my own use in an .ASP page
> >> >
> >> > any ways I am using the FilesystemObjects to get a directory and file
> >> > listing and generating a web page of that listing, but I need to filter
> >> > out
> >> > files with the SYSTEM tag, so it wont show files I dont want it to,
> >> > Below
> >> > is
> >> > my full code for the ASP page, I have Commented where I need to change
> >> > the
> >> > listing structure, if anyone can help me filter these out I would be
> >> > greatfull!!!
> >> >
> >> >
> >> > --- Begin code ---
> >> > <%@LANGUAGE="VBSCRIPT"%>
> >> > <%
> >> > Option Explicit
> >> > On Error Resume Next
> >> >
> >> > ' this section is optional - it just denies anonymous access
> >> > If Request.ServerVariables("LOGON_USER")="" Then
> >> > Response.Status = "401 Access Denied"
> >> > End If
> >> >
> >> > ' declare variables
> >> > Dim objFSO, objFolder
> >> > Dim objCollection, objItem
> >> >
> >> > Dim strPhysicalPath, strTitle, strServerName
> >> > Dim strPath, strTemp
> >> > Dim strName, strFile, strExt, strAttr
> >> > Dim intSizeB, intSizeK, intAttr, dtmDate
> >> >
> >> > ' declare constants
> >> > Const vbReadOnly = 1
> >> > Const vbHidden = 2
> >> > Const vbSystem = 4
> >> > Const vbVolume = 8
> >> > Const vbDirectory = 16
> >> > Const vbArchive = 32
> >> > Const vbAlias = 64
> >> > Const vbCompressed = 128
> >> >
> >> > ' don't cache the page
> >> > Response.AddHeader "Pragma", "No-Cache"
> >> > Response.CacheControl = "Private"
> >> >
> >> > ' get the current folder URL path
> >> > strTemp = Mid(Request.ServerVariables("URL"),2)
> >> > strPath = ""
> >> >
> >> > Do While Instr(strTemp,"/")
> >> > strPath = strPath & Left(strTemp,Instr(strTemp,"/"))
> >> > strTemp = Mid(strTemp,Instr(strTemp,"/")+1)
> >> > Loop
> >> >
> >> > strPath = "/" & strPath
> >> >
> >> > ' build the page title
> >> > strServerName = UCase(Request.ServerVariables("SERVER_NAME"))
> >> > strTitle = "Contents of the " & strPath & " folder"
> >> >
> >> > ' create the file system objects
> >> > strPhysicalPath = Server.MapPath(strPath)
> >> > Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
> >> > Set objFolder = objFSO.GetFolder(strPhysicalPath)
> >> > %>
> >> >
> >> > <html>
> >> >
> >> > <head>
> >> > <meta http-equiv="Content-Language" content="en-us">
> >> > <meta http-equiv="Content-Type" content="text/html;
> >> > charset=windows-1252">
> >> > <title></title>
> >> > </head>
> >> >
> >> > <body text="#C0C0C0" bgcolor="#000000">
> >> >
> >> > <div align="center">
> >> > <table border="0" width="80%" id="table1">
> >> > <tr>
> >> > <td align="center">Some web page Info here<p align="right"><b><font
> >> > size="4">And here</font></b></td>
> >> > </tr>
> >> > </table>
> >> > </div>
> >> > <p align="center">
> >> > <img border="0" src="Folder.jpg">
> >> > </p>
> >> >
> >> > <p align="center"><a href="../">Back</a></p>
> >> >
> >> >
> >> > <html>
> >> > <body>
> >> >
> >> > <div align="center"><center>
> >> > <table width="100%" border="0" cellspacing="1" cellpadding="2">
> >> >
> >> > <%
> >> > ''''''''''''''''''''''''''''''''''''''''
> >> > ' output the folder list
> >> > ''''''''''''''''''''''''''''''''''''''''
> >> >
> >> > Set objCollection = objFolder.SubFolders
> >> >
> >> > For Each objItem in objCollection
> >> > strName = objItem.Name
> >> > strAttr = MakeAttr(objItem.Attributes)
> >> > dtmDate = CDate(objItem.DateLastModified)
> >> > %>
> >> > <% Next %>
> >> >
> >> > <%
> >> > ''''''''''''''''''''''''''''''''''''''''
> >> > ' output the file list
> >> > ''''''''''''''''''''''''''''''''''''''''
> >> >
> >> > Set objCollection = objFolder.Files
> >> >
> >> > For Each objItem in objCollection
> >> > strName = objItem.Name
> >> > strFile = Server.HTMLEncode(Lcase(strName))
> >> >
> >> > intSizeB = objItem.Size
> >> > intSizeK = Int((intSizeB/1024) + .5)
> >> > If intSizeK = 0 Then intSizeK = 1
> >> >
> >> > strAttr = MakeAttr(objItem.Attributes)
> >> > strName = Ucase(objItem.ShortName)
> >> > If Instr(strName,".") Then strExt =
> >> > Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
> >> > dtmDate = CDate(objItem.DateLastModified)
> >> > %>
> >> > ' This is where I am listing the Files in my webpage, but it lists all
> >> > files, and I need to block the listing of system Files'
> >> > <tr>
> >> > <td align="left">A<%=strFile%></a></td>
> >> > <td align="right"> </td>
> >> > <td align="right">
> >> > <p align="left"><%=intSizeK%>K</td>
> >> > </tr>
> >> > <% Next %>
> >> >
> >> > </table>
> >> > </center></div>
> >> >
> >> > </body>
> >> > </html>
> >> > <%
> >> > Set objFSO = Nothing
> >> > Set objFolder = Nothing
> >> >
> >> > ' this adds the IIf() function to VBScript
> >> > Function IIf(i,j,k)
> >> > If i Then IIf = j Else IIf = k
> >> > End Function
> >> >
> >> > ' this function creates a string from the file atttributes
> >> > Function MakeAttr(intAttr)
> >> > MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-")
> >> > MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-")
> >> > MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-")
> >> > MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-")
> >> > End Function
> >> > %>
> >>
> >>
>

Re: Help with VB in an ASP script by Alex

Alex
Tue May 13 03:09:04 CDT 2008

Ah, I see what happened; you check attributes after doing all the formatting
work. Don't do that; the first thing you should do in the loop iterating
through the files is see if it's a system file. If it is, there's no point
in prepping its info for display. Notice below, I have the If test right
after the for...each opens. The "end if" statement closing it is then of
course immediately before your for...each closing "next" statement.

Set objCollection = objFolder.Files

For Each objItem in objCollection
If Not ( CBool(objItem.Attributes and 4) ) then

strName = objItem.Name
strFile = Server.HTMLEncode(strName)

intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Instr(strName,".") Then strExt = _
Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
dtmDate = CDate(objItem.DateLastModified)


"EQNish" <EQNish@discussions.microsoft.com> wrote in message
news:F23C837C-EDF6-4A3A-A0D3-8CC90359DE7D@microsoft.com...
> well... I have added the code like this:
> ''''''''''''''''''''''''''''''''''''''''
> ' output the file list
> ''''''''''''''''''''''''''''''''''''''''
>
> Set objCollection = objFolder.Files
>
> For Each objItem in objCollection
> strName = objItem.Name
> strFile = Server.HTMLEncode(strName)
>
> intSizeB = objItem.Size
> intSizeK = Int((intSizeB/1024) + .5)
> If intSizeK = 0 Then intSizeK = 1
> strAttr = MakeAttr(objItem.Attributes)
> strName = Ucase(objItem.ShortName)
> If Not ( CBool(strAttr and 4) ) then ' But right here, I'm not sure
> how to remove the Data'
> If Instr(strName,".") Then strExt =
> Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
> dtmDate = CDate(objItem.DateLastModified)
>
> As you can see in the rest of my code the HTML part uses strings from the
> VBScript to build the web page based on the file/directory structure. The
> <%
> Next %> statement is what makes the loop, everytime I put anything like
> your
> code in the loop fails. Also after looking at this as much as I can, I
> don't
> think I am even using the last two lines of code as I'm not using the file
> dates and I'm not 100% on what that second to last line above does. I do
> know anything I do with the If then Loops blows my for - next Loop
> completly
> out!... I'll keep digging, I'm also trying to figure a way to do allof
> this
> with one asp file in the Root Dir, instead of one in every sub-dir!!!! but
> I
> had to start somewhere and learn more then I know!!!
>
>
>
> "Alex K. Angelopoulos" wrote:
>
>> Are you sure you're doing that? The code you posted doesn't include the
>> if-then to filter out the system files.
>>
>> "EQNish" <EQNish@discussions.microsoft.com> wrote in message
>> news:09B444C9-F668-42D7-86D6-12B631E0EBF9@microsoft.com...
>> > Alex thanks for your help,
>> >
>> > I ahve tried to impliment what you said, but I can't get it to parse
>> > out
>> > the
>> > unwanted files! I think it has something to do with how I am writing
>> > the
>> > data to the web page:
>> >
>> > --- code begin ---
>> > <%
>> > ''''''''''''''''''''''''''''''''''''''''
>> > ' output the file list
>> > ''''''''''''''''''''''''''''''''''''''''
>> >
>> > Set objCollection = objFolder.Files
>> >
>> > For Each objItem in objCollection
>> > strName = objItem.Name
>> > strFile = Server.HTMLEncode(strName)
>> > intSizeB = objItem.Size
>> > intSizeK = Int((intSizeB/1024) + .5)
>> > If intSizeK = 0 Then intSizeK = 1
>> > strAttr = MakeAttr(objItem.Attributes)
>> > strName = Ucase(objItem.ShortName)
>> > If Instr(strName,".") Then strExt =
>> > Right(strName,Len(strName)-Instr(strName,".")) Else strExt = ""
>> > dtmDate = CDate(objItem.DateLastModified)
>> > %>
>> > '**** This is where the File data is writing to the HTML page, by using
>> > simple Strings and a Loop started above *** You can see creat a string
>> > for
>> > attributes called strAttr, for which the origanl script was writing
>> > the
>> > attribute to the html. I thought I could use that string to do my
>> > check,
>> > and
>> > remove that bit of data, however all I end up with is a bad page
>> > <tr>
>> > <td align="left"><%=strFile%></a></td>
>> > <td align="right"> </td>
>> > <td align="right">
>> > <p align="left"><%=intSizeK%>K</td>
>> > </tr>
>> >
>> > <% Next %>
>> >
>> > </table>
>> >
>> >
>> >
>> > "Alex K. Angelopoulos" wrote:
>> >
>> >> The file attributes is a bit mask setting, which means that boolean
>> >> operations can tell you whether or not the system flag is set. Hereâ??s
>> >> what
>> >> you do.
>> >>
>> >> When you get to the code chunk
>> >> Set objCollection = objFolder.Files
>> >>
>> >> For Each objItem in objCollection
>> >>
>> >> each objItem is a file. You can test objItem.Attributes to see if it
>> >> contains the value 4 for a System file, with an expression like this:
>> >> (objItem.Attributes and 4)
>> >> This returns 0 if the file does NOT have the system attribute set, and
>> >> a
>> >> nonzero value if it does. You need to force this to a simple
>> >> true-false
>> >> value, like this:
>> >> CBool(objItem.Attributes and 4)
>> >> The reason is that once it is true or false, using Not on it gives you
>> >> a
>> >> true if the file wasn't a system file but false if it was a system
>> >> file.
>> >> YOu
>> >> just wrap up the output inside an if-then statement testing the
>> >> attribute,
>> >> like this
>> >&