Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
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 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 June 9th, 2003, 01:25 PM
Authorized User
 
Join Date: Jun 2003
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
 
Old June 9th, 2003, 01:31 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
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
 
Old June 9th, 2003, 01:47 PM
Authorized User
 
Join Date: Jun 2003
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
 
Old June 9th, 2003, 01:59 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
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
 
Old June 9th, 2003, 04:32 PM
Authorized User
 
Join Date: Jun 2003
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
 
Old June 9th, 2003, 04:36 PM
Authorized User
 
Join Date: Jun 2003
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!
 
Old June 11th, 2003, 09:45 PM
Authorized User
 
Join Date: Jun 2003
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
 
Old May 6th, 2004, 12:21 PM
Registered User
 
Join Date: May 2004
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
 
Old April 9th, 2010, 04: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





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
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





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