Odd results getting files properties

A

Alan Webb

Can anyone explain to me why the list resulting from the
following code should return answers such as:

File Created Modified Accessed
Name 16/2/02 30/8/02 13/11/01

Needless to say it is the Accessed reply that throws me
being 3 months before the created date!!

'Code from here
Sub File_Spec()
Dim f
Dim pName As String 'Path name
Dim fName As String 'File name

pName = Application.GetOpenFilename(Title:="Select a file
in the directory to report on:")

For f = Len(pName) To 1 Step -1
If Mid(pName, f, 1) = "\" Then
pName = Left(pName, f)
Exit For
End If
Next f

fName = Dir(pName & "*.*")
ActiveWorkbook.Worksheets.Add
Cells(1, 1) = "File name"
Cells(1, 2) = "Date Created"
Cells(1, 3) = "Date Last Accessed"
Cells(1, 4) = "Date Last Modified"
Cells(1, 5) = "Path"

Do While (Len(fName) > 0)
fName = Dir()
If (Len(fName) > 0) And ((fName <> ".") And (fName
<> "..")) Then
ShowFileAccessInfo fName, pName
End If
Loop
Columns("A:E").AutoFit
End Sub

Sub ShowFileAccessInfo(filespec, pathspec)
Dim fs, f, s
Dim r
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(pathspec & filespec)
r = ActiveSheet.UsedRange.Rows.Count + 1
Cells(r, 1) = filespec
Cells(r, 2) = f.DateCreated
Cells(r, 3) = f.DateLastAccessed
Cells(r, 4) = f.DateLastModified
Cells(r, 5) = pathspec
End Sub
 
K

keepITcool

Alan,

First of all.. :
did you notice the first file never get's listed..?
move fname=dir() down to just before the loop and you're fine.

Next:
the dates on my system are correct,
but I suspect that it's related to a setting of the windows filesystem.

Several XP tuning/tweaking proggies allow you to turn off NTFS's
tracking of the last access date.



--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Alan Webb wrote :
 
A

Alan

keepITcool said:
Alan,

First of all.. :
did you notice the first file never get's listed..?
move fname=dir() down to just before the loop and you're fine.

Next:
the dates on my system are correct,
but I suspect that it's related to a setting of the windows filesystem.

Several XP tuning/tweaking proggies allow you to turn off NTFS's
tracking of the last access date.

Thanks, must admit I hadn't noticed but will have a look at that.

On the system I am using at work I shall not be able to check on the
access tracking so will have to live with that
 

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