Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default File Attributes Function

Hello,

Jacob Skaria recently provided the very helpful function pasted below. I
have a follow-up question, can the function also include a way to get other
attributes such as: Datecreated, DateLastModified, and DateLastAccessed?

Sub Macro()

MsgBox GetLatestFileName("c:\test")
MsgBox GetLatestFileName("c:\test", "ba*.txt")
End Sub

Function GetLatestFileName(strFolder As String, Optional strFilter As String)
Dim strFile As String, varDT As Variant

strFile = Dir(strFolder & "\" & strFilter, vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & "\" & strFile) varDT Then
varDT = FileDateTime(strFolder & "\" & strFile)
GetLatestFileName = strFile
End If
strFile = Dir
Loop

End Function

--
Thanks & Best Regards
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 91
Default File Attributes Function

On May 7, 2:45*pm, LeeL wrote:
Hello, *

Jacob Skaria recently provided the very helpful function pasted below. *I
have a follow-up question, can the function also include a way to get other
attributes such as: *Datecreated, DateLastModified, and DateLastAccessed?

Sub Macro()

MsgBox GetLatestFileName("c:\test")
MsgBox GetLatestFileName("c:\test", "ba*.txt")
End Sub

Function GetLatestFileName(strFolder As String, Optional strFilter As String)
Dim strFile As String, varDT As Variant

strFile = Dir(strFolder & "\" & strFilter, vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & "\" & strFile) varDT Then
varDT = FileDateTime(strFolder & "\" & strFile)
GetLatestFileName = strFile
End If
strFile = Dir
Loop

End Function

--
Thanks & Best Regards


Probably No

You may have to use FileSystemObject.

Ofcourse I will seek Jacob's view
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default File Attributes Function

I have code at http://www.cpearson.com/Excel/FileTimes.htm (with a
downloadable example at
http://www.cpearson.com/Zips/GetSetFileDateTime.zip ) that will get
the create date, last modify date, and last access date for a file.
Basically, the code wraps up a number of messy Win API functions and
structures into nice, neat, VBA-friendly functions.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]





On Fri, 7 May 2010 02:45:01 -0700, LeeL wrote:

Hello,

Jacob Skaria recently provided the very helpful function pasted below. I
have a follow-up question, can the function also include a way to get other
attributes such as: Datecreated, DateLastModified, and DateLastAccessed?

Sub Macro()

MsgBox GetLatestFileName("c:\test")
MsgBox GetLatestFileName("c:\test", "ba*.txt")
End Sub

Function GetLatestFileName(strFolder As String, Optional strFilter As String)
Dim strFile As String, varDT As Variant

strFile = Dir(strFolder & "\" & strFilter, vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & "\" & strFile) varDT Then
varDT = FileDateTime(strFolder & "\" & strFile)
GetLatestFileName = strFile
End If
strFile = Dir
Loop

End Function

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default File Attributes Function

As Javed mentioned I have modified using FSO..

Sub Macro()

Dim objFile As Object

'Set objFile = GetLatestFileName("c:\test")
Set objFile = GetLatestFileName("c:\test", "ba*.txt")

MsgBox "Latest File : " & objFile & vbCrLf & _
"Created : " & objFile.DateCreated & vbCrLf & _
"Modified : " & objFile.DateLastModified & vbCrLf & _
"Accessed : " & objFile.DateLastAccessed


End Sub

Function GetLatestFileName(strFolder As String, Optional _
strFilter As String) As Object
Dim fso As Object, objFold As Object, objFile As Object
Dim varDT As Variant, blnFilter As Boolean

Set fso = CreateObject("Scripting.FileSystemObject")
Set objFold = fso.GetFolder(strFolder)

For Each objFile In objFold.Files

blnFilter = False
If strFilter = "" Then
blnFilter = True
Else
If LCase(objFile.Name) Like LCase(strFilter) Then blnFilter = True
End If

If blnFilter Then
If objFile.DateLastModified varDT Then
varDT = objFile.DateLastModified
Set GetLatestFileName = objFile
End If
End If
Next

End Function

--
Jacob (MVP - Excel)


"LeeL" wrote:

Hello,

Jacob Skaria recently provided the very helpful function pasted below. I
have a follow-up question, can the function also include a way to get other
attributes such as: Datecreated, DateLastModified, and DateLastAccessed?

Sub Macro()

MsgBox GetLatestFileName("c:\test")
MsgBox GetLatestFileName("c:\test", "ba*.txt")
End Sub

Function GetLatestFileName(strFolder As String, Optional strFilter As String)
Dim strFile As String, varDT As Variant

strFile = Dir(strFolder & "\" & strFilter, vbNormal)
Do While strFile < ""
If FileDateTime(strFolder & "\" & strFile) varDT Then
varDT = FileDateTime(strFolder & "\" & strFile)
GetLatestFileName = strFile
End If
strFile = Dir
Loop

End Function

--
Thanks & Best Regards

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
File attributes Alan Excel Programming 6 January 8th 08 03:38 PM
Data value display attributes linked to table attributes MDT at Paragon Home Inspections, LLC Charts and Charting in Excel 0 November 15th 06 12:53 AM
Getting NTFS file attributes Kiran Excel Discussion (Misc queries) 1 August 4th 05 08:13 PM
File Attributes [email protected] Excel Programming 5 March 29th 05 05:06 PM
File Attributes dsti3 Excel Discussion (Misc queries) 1 February 10th 05 05:51 AM


All times are GMT +1. The time now is 07:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"