Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 19th, 2003, 12:42 PM
Registered User
Join Date: Jul 2003
Location: Tulsa, OK, USA.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to brandon1974
Default Get File Size into a variable

Hello everyone,

I need to get the size of a file and stick the value into a variable.

I can get the absolute path of the file in question, but when I try to use the FilSystem Object to get the file properties, I keep getting errors.

Here's where I am so far:


  dim cn
  dim cmd
  set cn = server.CreateObject("ADODB.Connection")
  cn.ConnectionString = MM_ConGL_STRING
  cn.ConnectionTimeout = 30

  cc_dld = request.QueryString("cc_dld") = "yes"
  sc_dld = request.QueryString("sc_dld") = "yes"
  s_dld = request.QueryString("s_dld") = "yes"

  ndlid = DMax("DLID","Downloads","") 'gets id of file previously inserted

  if cc_dld then
    id = BestLong(request.querystring("ccid")) 'BestLong converts string to number
  elseif sc_dld then
    id = BestLong(request.querystring("scid"))
  elseif s_dld then
    id = BestLong(request.querystring("sid"))
  end if

  filelink = DLookup("DLLink","Downloads","DLID=" & dlid) 'gets relative path of file
  filename = Right(filelink, Len(filelink) - InStrRev(filelink, "/", -1, 1))
  filepath = Server.MapPath("/gl/admin/documents/")
  filespec = filepath & "\" & filename
  dim objFSO
  set objFSO = server.CreateObject("Scripting.FileSystemObject")


I'll have some inserts and updates after I get the size of the file in 'filespec'

How can I get the size of the file specified in the absolute path 'filespec' into a variable that I can then insert into a table?

I've tried using objFSO.Size(filespec) but it doesn't like that. Does anyone know what I'm doing wrong?


Old July 22nd, 2003, 12:41 AM
Authorized User
Join Date: Jul 2003
Location: Athens, , Greece.
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts

Hello there,

I believe you are missing a part. After you create an instance to the FileSystemObject, you have to get the file.. The above code will do the trick :)

'***************** Size
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fileObject = fso.GetFile(Server.MapPath("\fso\") & "\myfile.txt")

Response.Write fileObject.Size & " bytes"

Set fileObject = Nothing
Set fso = Nothing


Kostas Lagos

Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrox File Share - 1g file size limit b67 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 May 7th, 2007 04:24 PM
file size dotnetprogrammer VS.NET 2002/2003 3 November 17th, 2004 01:33 AM
Trouble with file size, PLEASE HELP!!! brettk_1 ASP.NET 1.0 and 1.1 Professional 3 August 25th, 2004 07:41 AM
File size Scripts jemacc SQL Server DTS 3 July 18th, 2004 02:32 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.