Return To Home Page - Link to "The Wanker" - Contact Us


Return To Home Page

Show The Size Of A Directory Using ASP



This is an example of using the FileSystemObject to determine the total size of all files in a directory and any sub directories in it. This is handy because sometimes you might want to know just how big your web site is. Replace "somedirectory" with your directory name. If you know the physical path you can replace Server.MapPath("/somedirectory") with the actual path like so.
"E:\Inetpub\virtuals\somesite\somedirectory"

Here's the catch.
If you are using NT the directories you run this on must have the correct permissions. Basically the directories and all subdirectories within it all need "read" permissions from the anonymous account or you will get a permission denied error.

<%
Set MyFileSize = Server.CreateObject ("Scripting.FileSystemObject")
MyPath = Server.MapPath("/somedirectory")
Set MyFolder = MyFileSize.GetFolder(MyPath)
%>


<p><% =MyPath %> is <% =MyFolder.Size %> bytes</p>
 
The results might look something like this.

E:\Inetpub\virtuals\somesite\somedirectory is 47331 bytes


Banner
ASP (Active Server Pages) is a technology developed by Microsoft. Pages using ASP are primarily developed in JScript, or VBScript and are integrated into the HTML of your Web pages. The ASP code is compiled on-the-fly by the server and the resulting output is standard HTML. By using ASP, Web pages can be dynamic, full of ever-changing content, and browser independent.

 

Link to "The Wanker"
© 2007 CodeWanker - Active Server Pages Articles, Code Snippets, & Tutorials