Besides Form and Files collections,
UploadManager provides one more collection, Upload.Directory,
which represents all files and subdirectories of a directory on your hard drive.
The Directory collection consists of DirectoryItem objects.
Each DirectoryItem object represents a file or subdirectory inside
this directory. All the file and subdirectory items are always grouped
together, with subdirectories preceding files in the collection.
Within the subdirectory and file groups, items can be sorted by name,
type, size, creation time, last modification time and last access time.
The following code snippet creates and scrolls through a Directory
collection which represents all files in the folder "c:\mydir"
sorted by file type:
|
<%
<!--METADATA TYPE="TypeLib" UUID="{B4E1B2DE-151B-11D2-926A-006008123235}"-->
Set Upload = Server.CreateObject("Persits.Upload")
Set Dir = Upload.Directory( "c:\mydir\*.*", SORTBY_TYPE)
For Each item in Dir
Response.Write item.FileName &"<BR>"
Next
%>
|
The first argument of the Directory property is a directory name
and a file name which can contain wildcard characters (* and ?).
The second argument is optional and, if used, must be set to one of the
Sort-by values defined in the AspUpload type library. The default value is
SORTBY_NAME (numeric 1). The other valid values for the 2nd parameter
are SORTBY_TYPE (2), SORTBY_SIZE (3), SORTBY_CREATIONTIME (4),
SORTBY_LASTWRITETIME (5), and SORTBY_LASTACCESSTIME (6).
To use this and other constants defined in the AspUpload type library, use the metadata
tag
<!--METADATA TYPE="TypeLib" UUID="{B4E1B2DE-151B-11D2-926A-006008123235}"-->
The third argument is also optional. It is a Boolean value which
specifies whether to sort in an ascending (if set to True or omitted)
or descending (if False) order.
The code sample DirectoryListing.asp in conjunction with
the script download.asp demonstrates the directory listing
and download functionality of AspUpload.
DirectoryListing.asp
<HTML>
<HEAD>
<!--METADATA TYPE="TypeLib" UUID="{B4E1B2DE-151B-11D2-926A-006008123235}"-->
</HEAD>
<BODY>
<H3>Directory Listing</H3>
<%
If Request("Dir") = "" Then
Directory = "c:\"
Else
Directory = Request("Dir")
End If
Set Upload = Server.CreateObject("Persits.Upload")
Set Dir = Upload.Directory( Directory & "*.*", , True)
%>
<h2><% = Dir.Path %></h2>
<TABLE BORDER=1 CELLSPACING=0>
<TH>Name</TH><TH>Size</TH> <TH>Type</TH> <TH>Modified</TH> <TH>Created</TH><TH>Attr</TH><TR>
<% For Each Item in Dir %>
<% If Item.IsSubdirectory Then %>
<TD><B><A HREF="DirectoryListing.asp?Dir=<% = Server.URLEncode(Left(Dir.Path, Len(Dir.Path)-3)) & Server.URLEncode(Item.FileName) & "\" %>"><% = Item.FileName %></A></B></TD>
<TD><B>DIR</B></TD>
<% Else %>
<TD><A HREF="Download.asp?Name=<% =Server.URLEncode( Item.FileName )%>&File=<% = Server.URLEncode(Left(Dir.Path, Len(Dir.Path)-3)) %><% =Server.URLEncode( Item.FileName )%>"><% = Item.FileName %></A></TD>
<TD ALIGN=RIGHT><% = Item.Size %></TD>
<% End If %>
<TD><% = Item.FileType %></TD>
<TD><% = Item.LastWriteTime %></TD>
<TD><% = Item.CreationTime %></TD>
<TD>
<%
If Item.CheckAttribute( FILE_ATTR_READONLY) Then
Response.Write "R"
End If
If Item.CheckAttribute( FILE_ATTR_HIDDEN) Then
Response.Write "H"
End If
If Item.CheckAttribute( FILE_ATTR_SYSTEM) Then
Response.Write "S"
End If
If Item.CheckAttribute( FILE_ATTR_ARCHIVE) Then
Response.Write "A"
End If
%>
</TD><TR>
<% Next %>
</TABLE>
</BODY>
</HTML>
|
download.asp
<%
' AspUpload Code samples: download.asp
' Invoked by DirectoryListing.asp
' Copyright (c) 2001 Persits Software, Inc
' http://www.persits.com
' This file must not contain any HTML tags
Set Upload = Server.CreateObject("Persits.Upload")
Upload.SendBinary Request("File"), True, "application/octet-stream", True
%>
|
Click the link below to run this code sample:
http://localhost/aspupload/09_misc/DirectoryListing.asp