Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 9th, 2003, 02:25 PM
Authorized User
 
Join Date: Jun 2003
Location: St-Laurent, Quebec, Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get file size from VB?

Hello all,

I am writing a program to compress MS Access files on our networks.
I would like to know how can I get the file size and/or file modified date from my VB program.

I need to know these properties so I can decide if it is a zip or compress action that I should take.

Thank you


A.Delcy
Web Administrator
Canada
__________________
A.Delcy
Developer
Canada
Reply With Quote
  #2 (permalink)  
Old June 9th, 2003, 02:31 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

take a look at the file system object..

if will give you the info that you need...

you need a reference to microsoft scripting runtime to use it..

HTH...

Gonzalo Bianchi
Reply With Quote
  #3 (permalink)  
Old June 9th, 2003, 02:47 PM
Authorized User
 
Join Date: Jun 2003
Location: St-Laurent, Quebec, Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Gonzalo,

This is exactly what I am using in my program to copy, delete and move files around but it does not give me inforamtion about the file.

For example:

- I need to know the version of MS Access this file is associated with.
- The last time it was modified
- The size of that file
- Etc

I have not find anything from the microsoft scripting runtime library.

This is the first time I am using this library so if you have an example, please send it to me.

Below is what I am doing now:

Private Function IsFileExist(ByVal pstrFileName As String) As Boolean

On Error GoTo ERR_IsFileExist

    Set objFile = New Scripting.FileSystemObject
    IsFileExist = objFile.FileExists(pstrFileName)
    Exit Function

ERR_IsFileExist:
    IsFileExist = False

End Function

Private Function CreateNewFile(ByVal pstrFileName As String) As Boolean

On Error GoTo ERR_CreateNewFile

    Set objFile = New Scripting.FileSystemObject
    objFile.CreateTextFile pstrFileName, True
    CreateNewFile = True
    Exit Function

ERR_CreateNewFile:
    CreateNewFile = False

End Function

Thank you



A.Delcy
Web Administrator
Canada
Reply With Quote
  #4 (permalink)  
Old June 9th, 2003, 02:59 PM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

you are on the good track.. let's see..

you have some more objects inside the FSO...

you have.. file, files, folder, folders, drive, drives (objects with s are collections...)

mmm you have..

GetFileVersion(filename) gives you the version...

inspect the FSO and you will find all that you need...

if you have another question.. just ask again...

HTH...

Gonzalo Bianchi
Reply With Quote
  #5 (permalink)  
Old June 9th, 2003, 05:32 PM
Authorized User
 
Join Date: Jun 2003
Location: St-Laurent, Quebec, Canada.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can Dim the following:
Dim objFileProp As Scripting.Files

but I cannot set it to the new instance of the Files
E.g:
Set objFileProp = New Scripting.Files

See below, I think I am on the right track but...

Private Function GetFileSize(ByVal pstrFileName As String) As Long
    Dim strSize As String

On Error GoTo ERR_GetFileSize

    Set objFileProp = New Scripting.FileSystemObject
    strSize = objFileProp.Item(pstrFileName).Size
    GetFileSize = strSize
    Exit Function

ERR_GetFileSize:
    GetFileSize = strSize

End Function

Thank you



A.Delcy
Web Administrator
Canada
Reply With Quote
  #6 (permalink)  
Old June 9th, 2003, 05:36 PM
Authorized User
 
Join Date: Jun 2003
Location: Livermore, CA, USA.
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here you go, off the top of my head:

dim FSO as scripting.filesystemobject 'Set reference to Microsoft Scripting Runtime
set FSO = new scripting.filesystemobject
dim File as scripting.file

if FSO.FileExists(FILENAME) then
 Set File = FSO.GetFile(FILEPATH & "\" & FILENAME)

version = file.version
fileSize = file.size

OR:

set FSO = new s.filesystemobj
set FOLDER = fso.getfolder(DIRECTORY)
dim file as s.file
for each file in FOLDER.files
  version = file.version
  size = file.size
next

Have fun!
Reply With Quote
  #7 (permalink)  
Old June 11th, 2003, 10:45 PM
Authorized User
 
Join Date: Jun 2003
Location: Sydney, NSW, Australia.
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to alantodd
Default

A quick way to get just the size of the file is to open it for input, then call for it's size.

So:

open "File.one" for input as #1
x=LOF(1)
close #1

x now contains the size of the file in bytes.

:D
Reply With Quote
  #8 (permalink)  
Old May 6th, 2004, 01:21 PM
Registered User
 
Join Date: May 2004
Location: vadodara, gujarat, India.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kevin_javia
Default

You can use FileLen function of VB.

kevin javia
Reply With Quote
  #9 (permalink)  
Old April 9th, 2010, 05:52 PM
Registered User
 
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down OMG What are you Talking

So complicated, only to get the Filesize ????
Dont Load big Objects and open Filepointer, only for Filesize !!

BYTES = FileLen(FILENAME)

Best Wishes from Vienna
www.lookover.at
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 05:24 PM
Printer.Paper size problem in VB. :) venkatesh_anmca Access VBA 1 March 21st, 2005 04:09 AM
Excel VB workbook increasing in size bdancis Excel VBA 1 December 7th, 2004 04:23 PM
file size dotnetprogrammer VS.NET 2002/2003 3 November 17th, 2004 01:33 AM



All times are GMT -4. The time now is 01:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.