Getting the properties of a file

V

Vilem Sova

I need to be able to get some properties from files stored on a server (in
particular the date modified and size).

I've come across the FileSystemObject on the TheAccessWeb web site, but it
requires installing and registering dll's and VB runtimes and the like.

Is there another, simpler way to get these properties?

Thanks
Vilem Sova
 
D

Douglas J. Steele

The FileDateTime function will return the date and time the file was last
modified.

The FileLen function will return the length of the file in bytes.

Both functions take a single argument: the full path to the file.

Having said that, unless you're using really old operating systems, you
should be able to use FSO without any problems. It's not even necessary to
set a reference to it in Access: you can use Late Binding instead.

Sub UsingFSO(FilePath As String)

Dim objFSO As Object
Dim objFile As Object
Dim strOutput As String

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(FilePath)
strOutput = FilePath & " is " & objFile.Size & _
" bytes, and was last modified " & _
objFile.DateLastModified
MsgBox strOutput

End Sub

For what it's worth, I rarely, if ever, use FSO. Using APIs is significantly
faster. Tests I did enumerating files on a hard drive showed using APIs to
be an order of magnitude faster than using VBA functions, and the VBA
functions were an order of magnitude faster than using FSO.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top