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

June 9th, 2003, 01:25 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 9th, 2003, 01:31 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|
|

June 9th, 2003, 01:47 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 9th, 2003, 01:59 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
|
|

June 9th, 2003, 04:32 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

June 9th, 2003, 04:36 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

June 11th, 2003, 09:45 PM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

May 6th, 2004, 12:21 PM
|
|
Registered User
|
|
Join Date: May 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can use FileLen function of VB.
kevin javia
|
|

April 9th, 2010, 04:52 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|
 |