Persits Software, Inc. Knowledge Base Articles

Hiding the . and .. directories in the DirectoryListing.asp sample script

Problem Description

The code sample DirectoryListing.asp which comes with AspUpload displays all folders and files in a given directory, including the links to the current directory (".") and parent directory (".."). This article explains how to hide the "." and ".." links so that a user could not navigate to the parent directory.

Solution

The following simple modifications need to be made to the file DirectoryListing.asp:

1. A condition statement should be inserted at the beginning of the main For-Each loop, as follows:

<% For Each Item in Dir %>

<% If Item.FileName <> "." and Item.FileName <> ".." Then %>

<% If Item.IsSubdirectory Then %>

2. A matching End If statement should be added at the bottom of the main loop, as follows:

</TD><TR>

<% End If %>

<% Next %>