Get Date/Time Stamp from text file

S

Scott Strauss

I built an Access application that has a macro to back up
key tables to text files. I also have a restore macro
that empties these tables then imports data from the back
up text files.

Is there a way to read the date stamp from a text file so
I can display it on a form when the restore macro imports
the file?

Thanks!
 
J

John Nurick

Hi Scott,

You can use the FileSystemObject object, e.g.

Dim FSO As Object 'Scripting.FileSystemObject
Dim F As Object 'Scripting.File
Dim strDateStamp As String

Set FSO = CreateObject("Scripting.FileSystemObject")
Set F = FSO.GetFile("D:\Folder\File.txt")

strDateStamp = F.DateLastModified

Set F = Nothing
Set FSO = Nothing
 
S

Scott Strauss

Thanks John. This works great.
-----Original Message-----
Hi Scott,

You can use the FileSystemObject object, e.g.

Dim FSO As Object 'Scripting.FileSystemObject
Dim F As Object 'Scripting.File
Dim strDateStamp As String

Set FSO = CreateObject("Scripting.FileSystemObject")
Set F = FSO.GetFile("D:\Folder\File.txt")

strDateStamp = F.DateLastModified

Set F = Nothing
Set FSO = Nothing


I built an Access application that has a macro to back up
key tables to text files. I also have a restore macro
that empties these tables then imports data from the back
up text files.

Is there a way to read the date stamp from a text file so
I can display it on a form when the restore macro imports
the file?

Thanks!

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 
D

Douglas J. Steele

Wouldn't FileDateTime("D:\Folder\File.txt") do the same thing more
efficiently?
 
J

John Nurick

Thanks, Doug.

It would ... but the only function name I could remember was FileAttr(),
and I couldn't find the Access 2002 help topic on that - which might (or
might not) have directed me to FileDateTime() <g>.

Apart from that, FileSystemObject is sometimes useful because it offers
the Created and LastAccessed dates too.
 
S

Scott Strauss

Thanks for your help with this. It's exactly what I
needed.

Scott
-----Original Message-----
Hi Scott,

You can use the FileSystemObject object, e.g.

Dim FSO As Object 'Scripting.FileSystemObject
Dim F As Object 'Scripting.File
Dim strDateStamp As String

Set FSO = CreateObject("Scripting.FileSystemObject")
Set F = FSO.GetFile("D:\Folder\File.txt")

strDateStamp = F.DateLastModified

Set F = Nothing
Set FSO = Nothing


I built an Access application that has a macro to back up
key tables to text files. I also have a restore macro
that empties these tables then imports data from the back
up text files.

Is there a way to read the date stamp from a text file so
I can display it on a form when the restore macro imports
the file?

Thanks!

--
John Nurick [Microsoft Access MVP]

Please respond in the newgroup and not by email.
.
 
D

Douglas J. Steele

John Nurick said:
Apart from that, FileSystemObject is sometimes useful because it offers
the Created and LastAccessed dates too.

Agreed, although I always use API calls when I can. However, as far as I can
tell, FSO is the only way to get those dates for Folders.
 
J

John Nurick

Agreed, although I always use API calls when I can. However, as far as I can
tell, FSO is the only way to get those dates for Folders.

I just use the FSO; but in the directory entries where the timestamps
are stored, there's not much difference between a file and a subfolder.
And there must be an API function that can return folder timestamps, or
neither FSO nor Windows Explorer would be able to display them. So
(grabbing pipe and deerstalker) I infer that GetFileTime() must work for
both files and subfolders.
 
D

Douglas J. Steele

John Nurick said:
I just use the FSO; but in the directory entries where the timestamps
are stored, there's not much difference between a file and a subfolder.
And there must be an API function that can return folder timestamps, or
neither FSO nor Windows Explorer would be able to display them. So
(grabbing pipe and deerstalker) I infer that GetFileTime() must work for
both files and subfolders.


You'd think so, wouldn't you? However, I seem to recall that I tried a few
years ago for something I was building, and couldn't get it to work.
 
D

Douglas J. Steele

John Nurick said:
You got me curious enough to download and modify the sample VB project
at http://blackbeltvb.com/free/SETFTIME.ZIP. This seems to work on both.

See also
http://vbnet.mvps.org/index.html?code/fileapi/folderdatetime.htm

Thanks, John. I guarantee Randy didn't have that page back when I was
trying, as that's normally my first stopping place! I guess I didn't find
anything about FILE_FLAG_BACKUP_SEMANTICS when I was attempting to do this.
Of course, I don't need it anymore, but at least I'll know if I ever do
again.
 

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