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!

Bloody _vti's...

Status
Not open for further replies.

Webflex

Technical User
Apr 20, 2001
101
0
0
GB
I picked up this useful code from brainjar to parse a set of folders and display hyperlinks to the contents.

It does this really well but also includes the bloody _vti folders that FrontPage leaves lying around in the results.

I know I need to add someting like

Code:
 If InStr(1, objItem, "_vti", 1) = 0 Then

to get around it but I'm not sure of the location or correct syntax, the listing page code is below;

TIA

Code:
<%@ LANGUAGE="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<% '***************************************************************************
   '* ASP Directory Listing                                                   *
   '*                                                                         *
   '* Do not remove this notice.                                              *
   '*                                                                         *
   '* Copyright 1999, 2000 by Mike Hall.                                      *
   '* Please see [URL unfurl="true"]http://www.brainjar.com[/URL] for documentation and terms of use.  *
   '***************************************************************************
%>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
<head>
<title>Oracle Discoverer Reports</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="_style/csog.css">
</head>
<body>

<div id="demoBox">

<h3>Oracle Discoverer Reports</h3>

<p>Listed below are common reports available from Oracle Discoverer.</p>

</div>

<!-- List these three folders. -->
<ul>
<% ListFolderContents(Server.MapPath("AR Accounts Receivable")) %>
<% ListFolderContents(Server.MapPath("AP Accounts Payable")) %>
<% ListFolderContents(Server.MapPath("FA Fixed Assets")) %>
<% ListFolderContents(Server.MapPath("GL General Ledger")) %>
<% ListFolderContents(Server.MapPath("HR Human Resources")) %>
<% ListFolderContents(Server.MapPath("INV Inventory")) %>
<% ListFolderContents(Server.MapPath("OP Project Accounts")) %>
<% ListFolderContents(Server.MapPath("PO Purchasing")) %>
</ul>

</body>
</html>

<% sub ListFolderContents(path)

     dim fs, folder, file, item, url

     set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(path)

    'Display the target folder and info.

     Response.Write("<li><b>" & folder.Name & "</b> - " _
       & folder.Files.Count & " files, ")
     if folder.SubFolders.Count > 0 then
       Response.Write(folder.SubFolders.Count & " directories, ")
     end if
     Response.Write(Round(folder.Size / 1024) & " KB total." _
       & vbCrLf)

     Response.Write("<ul>" & vbCrLf)

     'Display a list of sub folders.
       

     for each item in folder.SubFolders
       ListFolderContents(item.Path)
     next
         
          
     'Display a list of files.

 
     for each item in folder.Files
       url = MapURL(item.path)
       Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> - " _
         & item.Size & " bytes, " _
         & "last modified on " & item.DateLastModified & "." _
         & "</li>" & vbCrLf)
     next

     Response.Write("</ul>" & vbCrLf)

     Response.Write("</li>" & vbCrLf)


   end sub
      
     

   function MapURL(path)

     dim rootPath, url

     'Convert a physical file path to a URL for hypertext links.

     rootPath = Server.MapPath("/")
     url = Right(path, Len(path) - Len(rootPath))
     MapURL = Replace(url, "\", "/")

   end function %>
 
You would use it inside any For Each....Next loop where you wanted to test for that specific folder.

Code:
For Each

If Instr(....)

Else

End If

Next

Paul
 
Thanks, tried that in a few places with variable results but not the desired one, any chance you could comment it in the code?

TIA
 
I have added an If statement in bold. You may need to add it to the other loop depending on where you are seeing the files, but the syntax should be correct.

Code:
<%@ LANGUAGE="VBScript" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/URL]
<% '***************************************************************************
   '* ASP Directory Listing                                                   *
   '*                                                                         *
   '* Do not remove this notice.                                              *
   '*                                                                         *
   '* Copyright 1999, 2000 by Mike Hall.                                      *
   '* Please see [URL unfurl="true"]http://www.brainjar.com[/URL] for documentation and terms of use.  *
   '***************************************************************************
%>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] xml:lang="en" lang="en">
<head>
<title>Oracle Discoverer Reports</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" type="text/css" href="_style/csog.css">
</head>
<body>

<div id="demoBox">

<h3>Oracle Discoverer Reports</h3>

<p>Listed below are common reports available from Oracle Discoverer.</p>

</div>

<!-- List these three folders. -->
<ul>
<% ListFolderContents(Server.MapPath("AR Accounts Receivable")) %>
<% ListFolderContents(Server.MapPath("AP Accounts Payable")) %>
<% ListFolderContents(Server.MapPath("FA Fixed Assets")) %>
<% ListFolderContents(Server.MapPath("GL General Ledger")) %>
<% ListFolderContents(Server.MapPath("HR Human Resources")) %>
<% ListFolderContents(Server.MapPath("INV Inventory")) %>
<% ListFolderContents(Server.MapPath("OP Project Accounts")) %>
<% ListFolderContents(Server.MapPath("PO Purchasing")) %>
</ul>

</body>
</html>

<% sub ListFolderContents(path)

     dim fs, folder, file, item, url

     set fs = CreateObject("Scripting.FileSystemObject")
     set folder = fs.GetFolder(path)

    'Display the target folder and info.

     Response.Write("<li><b>" & folder.Name & "</b> - " _
       & folder.Files.Count & " files, ")
     if folder.SubFolders.Count > 0 then
       Response.Write(folder.SubFolders.Count & " directories, ")
     end if
     Response.Write(Round(folder.Size / 1024) & " KB total." _
       & vbCrLf)

     Response.Write("<ul>" & vbCrLf)

     'Display a list of sub folders.
       

     for each item in folder.SubFolders
       ListFolderContents(item.Path)
     next
         
          
     'Display a list of files.

 
     for each item in folder.Files
[b]If Instr(1,item,"_vti")>0 Then
Else[/b]
       url = MapURL(item.path)
       Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> - " _
         & item.Size & " bytes, " _
         & "last modified on " & item.DateLastModified & "." _
         & "</li>" & vbCrLf)
[b]End If[/b]
     next

     Response.Write("</ul>" & vbCrLf)

     Response.Write("</li>" & vbCrLf)


   end sub
      
     

   function MapURL(path)

     dim rootPath, url

     'Convert a physical file path to a URL for hypertext links.

     rootPath = Server.MapPath("/")
     url = Right(path, Len(path) - Len(rootPath))
     MapURL = Replace(url, "\", "/")

   end function %>


Paul
 
You have 2 For Each loops.

The comments already in your code say that the first is for folders and the second for files.

I'm guessing it goes with the files...
 
Oh, heh yeah. Paul pretty much spelled it out.
 
_vti* files are typically hidden. Can you exlude them by checking Folder.Attributes mask (2nd bit from right)?

------
heisenbug: A bug that disappears or alters its behavior when one attempts to probe or isolate it
schroedinbug: A bug that doesn't appear until someone reads source code and realizes it never should have worked, at which point the program promptly stops working for everybody until fixed.

[ba
 
Thanks all, needed it in 2 places

Code:
     for each item in folder.SubFolders
     If Instr(1,item,"_vti")>0 Then
     Else
       ListFolderContents(item.Path)
	End If
     next
         
          
     'Display a list of files.

 
     for each item in folder.Files
	If Instr(1,item,"_vti")>0 Then
	Else
       url = MapURL(item.path)
       Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> - " _
         & item.Size & " bytes, " _
         & "last modified on " & item.DateLastModified & "." _
         & "</li>" & vbCrLf)
	End If
     next

     Response.Write("</ul>" & vbCrLf)

     Response.Write("</li>" & vbCrLf)


   end sub
 
I use this script to delete my vti's.

DeleteFp.vbs
Code:
Sub DeleteFPExtensions( path )
	Dim ofs, of, folder
	
	' This puff line of code makes it all work
	On Error Resume Next
	Set ofs = CreateObject( "scripting.filesystemobject" )
	Set of = ofs.GetFolder( path )
	For Each folder In of.SubFolders
		If left( folder.name, 1 ) = "_" Then
			folder.delete true
		End If
		' Recursive call
		DeleteFPExtensions folder.path
	Next
	Set of = nothing
	Set ofs = nothing
	Exit Sub
	
	' Error handling
	If Err.number <> 0 then
		msgbox( Err.Number & Err.description )
	End If
End Sub

Dim oArgs
Set oArgs = WScript.Arguments
For I = 0 to oArgs.Count - 1
	DeleteFPExtensions Trim( oArgs(i) )
Next
WScript.Echo( "Done!" )
 
Quick word of caution: The above code deletes folders if their name begins in the underscore character.

If you have intentionally named any folders this way, for example to hide them from directory browsing or front page search & table of conents... those folders will also be deleted by the code above.
 
LOL, my god man. They should give you a warning icon.

Don't you think that is fairly obvious?
Perhaps I am just naive.

*wonders who would =ever= use a naming conventions with leading underscores*
 
I gave you 2 or 3 examples of how it is used.

I'm not picking on you, JSpicolli. Your code is fine. I was just adding a little warning for people that perhaps are not knowledgeable about these things.

A lot of people get into ASP because they want more than FrontPage can give them. Not everyone enters from the angle of an experience software developer extending his applications to the web.
 
*wonders who would =ever= need more then 640k of memory*

Who-da thunkit.
???

I don't understand your comparison. Memory has changed based on need. There is no need to use a naming convention that prefixes your VD's with an underscore.

This type of naming convention is more like naming your stored procedures with 'sp_' prefixed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top