ASPFAQs.com
Your source for ASP-related frequently asked questions and answers!


4GuysFromRolla.com : ASP FAQS : FileSystemObject

Question: How can I determine the file size of a file on the Web server?

Answer: The FileSystemObject contains a library of objects, one of which is the File object. This object, as its name suggests, provides information relating to a file on the Web server. One of the properties of the File object is Size, which returns the size of the file in bytes. The FileSystemObject contains a method, GetFile(FilePath), which will return a File object that represents the file specified by FilePath.

So, putting this all together, we can get the size, in bytes, of a file on the Web server with the following code:

'What is the path of the file whose size you're interested in?
Dim strFileName
strFileName = "C:\FooBar\blah.txt"

'Create an instance of the FileSystemObject
Dim objFSO
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Get a file object
Dim objFile
Set objFile = objFSO.GetFile(strFileName)

'Get the file size
Dim iFileSize
iFileSize = objFile.Size

Fairly straightforward. Be sure to check out the live demo to see this code in action! Also be sure to check out the FileSystemObject FAQ category for more FSO-related FAQs!

-- View the technical docs for GetFile
-- View the technical docs for the File object
-- View the technical docs for the Size property

Happy Programming!


FAQ posted by Scott Mitchell at 2/2/2001 12:34:49 AM to the FileSystemObject category. This FAQ has been viewed 53,875 times.


Copyright 2017 QuinStreet Inc. All Rights Reserved.
Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers