Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

VBA To Read Modified Date Of .txt File

I have been searching for code that will read the modified date of a certain .txt file (without opening it, if possible) and if it <> Now then exit the function.

I have found information regarding MS Word documents, but this is just a simple txt file. Any help or redirection would be greatly appreciated. Thank you.

View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read File Last Modified Date

Is there other way to read a text file last modified date besides using the file system object as I access my file through a UNC path so the file system object can't work.

Thanks in advance.

Read A Text File Last Modified Date

Is there other way to read a text file last modified date besides using the file system object as I access my file through a UNC path so the file system object can't work.

Thanks in advance.

File Information Get Path ,filename,filesize,access Date ,modified Date
This tiny zip file have filename,filepath,fileaccess date,file modified date
if picture file then size of the picture

Thanks guys

bellow code
Private Const OF_READ = &H0&
Private Declare Function lOpen Lib "kernel32" Alias "_lopen" (ByVal lpPathName As String, ByVal iReadWrite As Long) As Long
Private Declare Function lclose Lib "kernel32" Alias "_lclose" (ByVal hFile As Long) As Long
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long

Dim lpFSHigh As Long
Private fileN As String
Private fileP As String
Private fileS As Double
Private fileC As String
Private fileA As String
Private fileH As Long
Private fileW As Long
Private fileX As String
Dim fs As Scripting.File
Private Sub Command1_Click()
Call commonDialogCall
Call GetFileS(fileX)
Call FileWHget
Call FileDateGet
Call displayall
End Sub
Public Sub displayall()
Label1.AutoSize = True
Label2.AutoSize = True
Label3.AutoSize = True
Label4.AutoSize = True
Label5.AutoSize = True
Label6.AutoSize = True
Label7.AutoSize = True

Label1.Caption = "File name = " & fileN
Label2.Caption = "File path = " & fileP
Label3.Caption = "File size = " & fileS & " Byte"
Label4.Caption = "File Created = " & fileC
Label5.Caption = "File Accessed = " & fileA
Label6.Caption = "File height = " & fileH
Label7.Caption = "File Widht = " & fileW
End Sub
Public Sub commonDialogCall()
CommonDialog1.Filter = "*.bmp"
fileX = CommonDialog1.FileName
fileN = CommonDialog1.FileTitle
fileP = Left(CommonDialog1.FileName, Len(CommonDialog1.FileName) - (Len(CommonDialog1.FileTitle) + 1))
End Sub
Public Sub GetFileS(FilePath As String)

Dim Pointer As Long, sizeofFile As Long
Pointer = lOpen(FilePath, OF_READ)
'size of the file
sizeofFile = GetFileSize(Pointer, lpFSHigh)
fileS = sizeofFile
lclose Pointer
End Sub
Private Sub FileDateGet()
Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(fileX)
fileC = f.DateCreated
fileA = f.DateLastModified
End Sub

Private Sub FileWHget()
Dim pic As Picture
Set pic = LoadPicture(fileX)
fileH = pic.Height
fileW = pic.Width
End Sub

Private Sub Command2_Click()
End Sub

Get Date Created And Date Modified Of A File
How to get the Date Created and Date Modified of a File using API Calls ???

Sort The File According To The Date Modified

I'd like to organize all the file in "c: est" directory in the list according to creation date and time. The files which located in c: est might have different ext such as .txt, .doc or .xls file.

Name Type Date Modified
1) a.doc Microsoft Word Document 10/Oct/2005 8.30pm
2) b.xls Microsoft Excel Worksheet 12/Jun/2005 8.00am
3) c.txt Text Document 08/Jul/2005 4.30pm
4) d.doc Microsoft Word Document 09/Nov/2005 8.30pm
5) e.doc Microsoft Word Document 09/Nov/2005 9.30pm

The correct result should show me as below.
Name Type Date Modified
1) e.doc Microsoft Word Document 09/Nov/2005 9.30pm
2) d.doc Microsoft Word Document 09/Nov/2005 8.30pm
3) a.doc Microsoft Word Document 10/Oct/2005 8.30pm
4) c.txt Text Document 08/Jul/2005 4.30pm
5) b.xls Microsoft Excel Worksheet 12/Jun/2005 8.00am


Get File Last Modified Date - A Quicker Way??
This works, but is EXTREMELY slow...

Set fs = New FileSystemObject
sPath = File2.Path & ""
For i = 0 To File2.ListCount - 1
Set f = fs.GetFile(sPath & File2.List(i))
d = f.DateLastModified
'do more stuff
Set f = Nothing
Set fs = Nothing
Is there a way without having to use FSO that is faster?


Reporting A File Modified Date
Can anyone help?

I am working on a program to report operating information in a number of categories. I would like to include a line on every report indicating the date the underlying Access table was last modified.

I know that I can use a blank formula in Crystal Reports 8.5 and fill it in VB6 with some text and the date but I cant get the date to work right. VB does have a "DateLastModified" property but the instructions for its use in the "Help" system left me baffled.

All I really need is the code to extract the date into a variable.

Check Dbf File Modified Date
Is it possible to check the dbf file modified date through VB6 by connecting to a database that is linked to the dbf file? If so how can I do it?

Open File By Date Modified
Good morning guys and gals...

So, i've got this code to generate a .zip file, how do I make it so when the open file window opens, the files inside are already arranged by details and by Date Modifed (last modified first)....
VB Code:
Private Sub btnComprimir_Click()StatusBar1.Panels(2).Text = ""StatusBar1.Panels(3).Text = ""StatusBar1.Panels(4).Text = "" StatusBar1.Panels(1).Text = "Comprimir" Dim cc As New GCommonDialogDim sFIle As String    If (cc.VBGetOpenFileName(sFIle, , , , , , "All Files (*.*)|*.*", , , "Escoge el archivo para comprimir", , Me.hwnd)) Then      With m_cZ         .Encrypt = (chkEncrypt.Value = vbChecked)         .ZipFile = Left$(Dir(sFIle), InStrRev(Dir(sFIle), ".")) & "zip"         .StoreFolderNames = False         .RecurseSubDirs = False         .ClearFileSpecs         .AddFileSpec sFIle         .Zip               If (.Success) Then            MsgBox "El archivo fué comprimido con la contraseña", vbInformation, "Comprimir"            Shell "Explorer c:mmm", vbNormalFocus         Else            MsgBox "Error, el archivo no fué comprimido", vbExclamation, "Comprimir"         End If            End With   End IfEnd Sub

VB File Sort By Modified Date
I added dircmd with /od in environmental varibles and could see that the files in a directory are sorted by modified date using DOS command prompt.
When I use the Dir in VB it still is getting the files in alphabetical order not by modified date. Any clue how to change the sort order while accessing the files using Dir.
Appreciate any help.

Help - Check File Last Modified Date Using Dll

I'm desperate to find a way to check the last modified date of an exe using a call to a dll or something like that.

I'm able to do it using filesystemobject but when I run the program on win95 machines it gives me a error 429 and can't figure out what it is. I've made a setup.exe using the deployment wizard and the program still doesn't run.

Can anyone post some code to get the data & file an exe was last modified by making a call to some windows dll?

All help with this matter is greatly appreciated.


Modified Date&amp;Time Of A File
Is there an easy way to get the date & time of the file without using the FSO?

How To Find The A File's Last Modified Date
How is it possible to find a file's last modified date without using FileSystemObject?

I ask this because my program has to run on XP and Win98, and so far as I am aware FSO will not run on Win98.

Any help would be appreciated.

Need To Check The Date-modified Of A File
I have a PDF file in C:/SAMAN/CSTMT.PDF

Ned to chek weather this the latest (today's) by the modified date. Please let me know how can I do that.


RE:Modified Date And Time Of A File
for retrival of filetime as a Double use the CDBL function. The date is the Whloe number the time is the fraction.


MsgBox CDbl(FileDateTime("C:Autoexec.bat"))

How To Access The Last Modified Date Of A File Using VB
How can I access the last modified date of a file through VB code.


Modifying The 'Date Modified' Attribute Of A File
I found plenty of links on how to access the 'Date Modified' of a file, however, what I need is to be able to modify that date programatically.

I tried simply renaming the file, but that didn't seem to affect the 'Date Modified'

If anyone can help, I'd appreciate it

What Is The Function To Get The Last Modified Date Of An Excel File?
What is the VBA function to get the last modified date of an excel file? How to compare dates, with < and >?

Copied File - Change Date Modified?
im creating this prog (almost done), its called "playlist extractor", it copies the files from a mp3 playlist to a folder u tell it, but i want it to change the date modified of the file to the time when it was copied, so it can be sorted in explorer.


Sort File Lists By Date Modified
How do I sort a file list so that the most recently modified file in a directory is listed first and vise versa?

Text File Modified Date Search

I have an VB application which stores client information in a text file. Is it possible to run some sort of query to select those records where the text file hasn't been modified for 30 days? I then need it to bring back a list of the filename of each text file that hasn't been edited for 30 days.

Any help would be appreciated.

How To Modify Date Created, Modified, Last Accessed Of A File?
Hi, does anyone knows how to change a file's date created, modified, last accessed attributes of a file?
Thank you

FileCopy NTFS To FAT32 Changes File's Modified Date
I've just been bitten by an annoying quirk, experienced on 2 different WindowsXP systems.

When copying a file from an NTFS partition to a FAT32 device, the new file's modified date is sometimes changed by 1 or 2 seconds.
This became apparent in a file syncronization program I have that compares mod dates and copies newer files over the older, and in this case can never catch up since the mod date is a moving target.

Only some files do this, and they do it consistently. It seems to have something to do with the original mod date value, maybe different number systems are rounding or something??

I tried doing a drag-n-drop copy within Windows Explorer and it did the same thing.

Anyone else see this behavior?


How To Get The Date Of &"last Modified&" Of A File?
hi guys
well i wanna know how can i get the date of "last modified" of a file. can u help me?

Date Modified
Hi All,

Can anyone please tell me which is better to use to get the last date a file was modified and why?

CreateObject("Scripting.FileSystemObject").GetFile(StrFile).DateLastMo dified


GetFileName API



What is the main difference?


- George

Modified Date
I want to tack on the end of a file that I have created the modified date. Right now I put on the end of the file ".tmp". But I really want to grab the date that the file was first modified. Is there a way to do this?

Here is what I have so far:
tmpFilName = "ADV_" & lstRRno & "_" & Mid$(inFilName, 1, 15) & ".tmp"

Thanks in advance,

Getting URL's Last Modified Date

How to get the last modified date of a URL.
Cause I need to do a program that read in the URl that a person type and display out the last modified date.


Date Last Modified
I've written a VB program that:

1. Opens an Excel File;
2. Changes information in the Properties submenu (under the File menu);
3. Saves the file, and then;
4. Closes the file.

This is all that the program does.

I was wondering if it is possible to do everything above and NOT change the "Date Last Modified" of the file. Any help would be greatly appreciated.


Folder Date Modified
I am writing a macro to find the date that the contents of a folder was last modified. Very simple using fso's ".datelastmodified". But then I noticed that the modified dates for the files in the folder were later then that of their folder.

How does Windows determine the Last Modified Date for folders? I assumed it was the latest date of its files.

Does this mean I have to loop thru all the files in the folder to get the real last modified date?

Syntax For Date Modified?

I'm using Excel 2003. I have a workbook (utility.xls) which cycles through all of the open workbooks (except itself) and extracts a number from Cell A1 and displays a running total in cell A1 of utility.xls.

Next, I want to put the names of the workbooks I'm extracting from and the dates they were last modified in some cells in utility.xls. Here is the code:

Private Sub CommandButton1_Click()
Dim UTIL, BOOK As Object
Set UTIL = Workbooks(ActiveWorkbook.Name).Sheets("Sheet1")
For Each wb In Application.Workbooks
Set BOOK = wb.Sheets("Sheet1")
If wb.Name = ActiveWorkbook.Name Then GoTo 100:
UTIL.Cells(1, 1) = UTIL.Cells(1, 1) + BOOK.Cells(1,1)
UTIL.Cells(2, 1) = wb.Name
UTIL.Cells(2, 2) = wb.DateModified
Next wb
End Sub

Any suggestions on how to modify the PROBLEM line in order to make it put in the date the workbook was last modified? I've tried variations such as .LastChanged, .LastModified. Ideas?
(NOTE: The preceeding line where I display the name works fine. I think it's just a syntax problem: "Object doesn't support this property or method.")

Thanks in advance.

Check Last Modified Date

I would like a solution where i can check a file on the last modified date of the file as well as call the time different between the time Now() with the last modified date. How can this be possible. Please help!


Disk Last Modified Date?

I was wondering if there is an easy way to get the last time a disk was modified? Such a property doesn't seem to exist in the fso.drives object.

I'm writing a disk cataloguing program, and it would be handy if I could write this property into my database, so I can compare it when the disk is inserted again.

Principally, I am cataloguing my CDs and DVDs - so perhaps I could look at whether the disk has been closed (in which case I know it will not get modified again), but it would be handy to pick up changes on disks that have not been closed.

I realise that I could just compare files in my database with the ones on the disk, but it would be pretty slow!



Sort By Date Modified?
I have an app that runs through a directory and strips files of data..
I need to figure out a way to loop through the files in order of date modified.. not Filename

using the x = Dir() function.. they are in order of filename..

How can I do this by date?


Files Last Modified Date

I'm making an Auto Update program for an app Im working on. The app will check on a url to see if a text file stored is a newer date than the one stored on the computer. If so, then the file will be replaced. Im ok downloading the file, but Im having problems getting the date of the file stored in the url.
I would of used the filesystemobject, but I can't seem to find this in
I've tried using the FileInfo class, but that doesn't support using url's.
Any ideas???

Ctrl+Alt+Del In XP + Modified Date
hey, two thinks.

1) In WinXP how can i remove my application from the Ctrl+Alt+Del list ? the old method for Win98 (RegisterServiceProcess) doesnt seem to work.

2) How can i change the date created/modified of a program ?

- Cheers

Get FileName Of Last Modified Date
Dear VBA expert,

I am stuck with this how to get the filename of the LastModifiedDate and input the filename to a cell. I managed to open it from C:Data, copy 2 sheets over but was unable to place the filename in cell IV2. I hope someone can help me on this. Any help is greatly appreciated.

CODESub GetLastModifiedFileName()
Dim fs As FileSearch, ws As Worksheet, i As Long, loc As Long, fdt As Double
Dim wsh As Worksheet
Set fs = Application.FileSearch
    With fs
        .SearchSubFolders = False
        .FileType = msoFileTypeExcelWorkbooks
        .LookIn = "C:Data"
        If .Execute > 0 And .FoundFiles.Count > 0 Then
            loc = 0
                For i = 1 To .FoundFiles.Count
                       If FileDateTime(.FoundFiles(i)) > fdt Then loc = i
                Next i
               Workbooks.Open .FoundFiles(loc)
            Exit Sub
        End If
    End With
    Sheets(Array("Region", "Output")).Select
    Sheets(Array("Region", "Output")).Copy After:=Workbooks("TEMPLATE.xls").Sheets(1)  
    Sheets(1).Range("IV3") = Environ("Username")
    Sheets(1).Range("IV4") = Now()
End Sub

Properties - Last Modified Date
Does anyone know how to amend the last modified properties of Access 2000 database?


Set Date Created/Modified Property
is there any way to override the date assigned to a file by windows and replace it with another one (such as after copying a file - the date modified is often before the date it was copied). i am using a fuction to backup a variety of database applications and another to clean out backups that are more than one month old, but have found that the date created/modified setting on the files does not match the date of import (which i marked in the file name). i do realize that i could use the date in the file name along with some string maniputation and a type conversion for my date comparison condition, but would like to avoid the extra overhead as this function is run automatically on the applications' startup (to avoid making backups for days the app isn't even used).

Last Date/Time Modified (noob)
Ok, as a mod of a nissan forum I hate when noobs ask a question without searching first and I might have searched for the wrong thing or in the wrong area, but searching on google didn't seem to work, yet it lead me here.

I am trying to accomplish something fairly simple and I'm a C developer and no very little about VB.

I have a basic excel spreadsheet and want one cell to contain the date and time of when the file was last modified. I found a few examples using the WorkBook_Changed function and one saying I should use WorkBook_Saved function yet neither are running and I have absolutely no clue what i'm doing. I've never written code for an Excel spreadsheet so I don't know if I'm putting the function in the wrong place or if I'm writing it wrong. Any and all help is welcome.



Reading A Directory By Modified Date
I am working on an application where I have to read every file in a directory, where the date time stamp is less than a stored date time stamp. Is their a way to set the directory to be in ascending modified order and then use the dir function to read the files where the date is less. I need to do this because the directory can contain more than 100,000 files. I don't want to read files that have already been updated.

When I read the file with the date time stamp that is less than I have to modify the file and I rewrite it with a the current date time stamp.

Thanks in advance

Getting The Modified Date From Excel Document
We have about 500 excel documents that stored that date of the document as
now(). (or current date it is modified) We want to hard code the date
instead of storing it like this so it will never change in the future if we
open it up again. The only date we know that it was open for sure is if you
look at the properties of the file and check the last modified. Does anyone
know of a way to pull in the date modified of an excel document and then
store that to a particular cell in the document. The main part I'm asking
about it retrieving the modified date of the document.


Joel Foudy

Output Date Modified If Data Is Entered

I'm currently creating an excel programin which i want to create some vb code that will check to see if a particular row's (from C to AA) cell has been modified and to then output that modification date to the corresponding row's AB cell. So for instance...if someone modifies the cell H7...then the modification date would be outputted to AB7. I have approximately 100 rows of data that needs this to be done for, and I can get the code to work for an individual row, but I cant figure out how to have it check all the rows in my spreadsheet and output it to the corresponding row. Here is my code for outuputting row 7:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Dim KeyRows As Range
Dim X As Variant

' The variable KeyCells contains the cells that will
' cause an alert when they are changed.

Set KeyCells = Range("D7:AA7")

If Not Application.Intersect(KeyCells, Range(Target.Address)) _
Is Nothing Then

[AB7].Value = "This order was last modified on " & Format(Now, "dd/mm/yy")

End If
End Sub

Any ideas? Thank you so much!


Seraching For Files And Verify Their Modified Date.
I'm current working on a project, where I need to be able to search for two files, on a network drive, if the files are their then find out if the files Mod. date, is todays date. If so then to xyz.

I want to do this in VB script, so i can just run a schudule, to do this task, if it pass then i can tell it to send me an email.

Can anyone help me?

Redate Last Modified Date In Batch Script
I am a newbie to MS Word and have converted several thousand lotus wordpro files to word which date stamped them with conversion date. I have written a successful script which rewrites a single .doc files modified date back to the date of the original .lwp file.
Can a willing member guide me how to pass the batch of file names into the script so that a loop or for next statement will rewrite the batch of files.

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "

Set colFiles = objWMIService.ExecQuery _
("Select * from CIM_Datafile Where name = 'c:\temp\test.lwp'")

For Each objFile in colFiles
Wscript.Echo "Name: " & objFile.Name
Wscript.Echo "File name: " & objFile.FileName
Wscript.Echo "Extension: " & objFile.Extension
Wscript.Echo "Last modified: " & objFile.LastModified

'# Script for resetting each WORD .DOC files property modified date to each
'# original LOTUS *.LWP files modified date after bulk conversion utility

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFilelwp = objFSO.GetFile("c: emp est.lwp")
Set objFiledoc = objFSO.GetFile("c: emp est.doc")

Wscript.Echo "LWP original file - Date last modified: " & objFilelwp.DateLastModified
Wscript.Echo "DOC converted file - Date last modified: " & objFiledoc.DateLastModified
Wscript.Echo "DOC converted file - Filename: " & objFiledoc.Name

Dim newDate, file
file = "c: emp est.doc"

'# Pass the date variable into the subroutine: modifyDateMod

newDate = objFilelwp.DateLastModified

Call modifyDateMod (file, newDate)

Sub modifyDateMod(strFilePath, newDate)

Dim sh, sf, fi
Dim Dir, File, pos

pos = InstrRev (strFilePath, "")
Dir = Left(strFilePath, pos)
File = Mid (strFilePath, pos+1)

'# Get FolderItem
Set sh = CreateObject ("Shell.Application")
Set sf = sh.NameSpace (Dir)
Set fi = sf.ParseName (File)

'# manipulates the FolderItem's Last-Modificaton-Date
fi.ModifyDate = newDate

End Sub

How To Sort Files Based On Date Modified
does any one has an idea how to sort files in a specific folder based on date modified. i want to list file names in list box sorted by date modified desc.

I will appreciate any contribution

Modified Date Of Table (Structure And Data)
I modified a few tables, and added data to a few tables. Both within SLQ Server or Query Analyzer.

Is there a way to display the 'Last modified' dates of my tables. I have 900 tables, and I forget which ones I modified!

I'm guessing it's a query to a system table, but I dunno which one, nor do I have time to flounder through there for 5 hours. I'm hoping a DBA that is allowed to flounder through there on company-time can tell me where to look


FROM sysobjects
WHERE (refdate > '9/1/06') AND (xtype = 'U')
ORDER BY refdate

yea, so there. (I thought there were a lot more than 21 tables...)

Dave Applegate
Microsoft VB MVP, ACE [FAQs]
My friend has a trophy wife, but apparently she wasn't in first place.

Edited by - Metallisoft on 9/7/2006 2:05:59 PM

Logged On User And Visited Sites + Modified Date

Three quick q's:

1 - How can i find the name of the currently logged on user (win 98 machine with the different user thingie) ?

2 - How can i find the currently viewed web page or be able to get the web pages that have been viewed (internet explorer 5) ?

3 - How can i change the modfied and created dates of a file ?


Need To Delete Folder And Contents Based On Modified Date
I'm not a programmer .... Technical User. I found the below script to delete files after 30 days. I hope the script will delete a folder and all its contents based on modified date

NumberOfDaysOld = 30
strPath = "C:Test"
Set objFSO = CreateObject("Scripting.FileSystemObject")  
Set objFolder = objFSO.GetFolder(strPath)
Set colSubfolders = objFolder.Subfolders
Set colFiles = objFolder.Files

For Each objFile in colFiles  
   If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then  
   End If  

For Each objSubfolder in colSubfolders    
   Set colFiles = objSubfolder.Files  
   For Each objFile in colFiles  
       If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
       End If


Copyright © 2005-08, All rights reserved