Function fileExists(s_directory As String, s_fileName As String) As Boolean
Dim obj_fso As Object
Set obj_fso = CreateObject("Scripting.FileSystemObject")
fileExists = obj_fso.fileExists(s_directory & "\" & s_fileName)
End Function
但我真的不知道如何检查同名文件是否更新。 我可以直接在文件名中使用版本,但它并没有解决我的问题,因为我的例如excelApp_0.1.xlsm无法知道,如果较新的搜索版本将是v0.2或0.8或1.6。你有什么建议吗?
答案 0 :(得分:1)
使用obj_fso.getFile(filespec)
获取FILE对象,然后使用file.DateCreated
。
答案 1 :(得分:0)
感谢UncleO,它有效: - )
Function newerFileExists(s_directory As String, s_fileName As String) As Boolean
Dim obj_fso As Object
Set obj_fso = CreateObject("Scripting.FileSystemObject")
Dim fileExists As Boolean
fileExists = obj_fso.fileExists(s_directory & "\" & s_fileName)
If fileExists Then
Dim file As Object
Dim s As String
Dim currentDate As Object
Dim newerDate As String
Set file = obj_fso.getFile(s_directory & "\" & s_fileName)
Set currentDate = ActiveWorkbook.BuiltinDocumentProperties("Creation Date")
newerDate = file.DateCreated
's = "Current file creation date: " & currentDate & vbCrLf
's = s & "Newer file creation date: " & newerDate
'MsgBox s
If newerDate > currentDate Then
newerFileExists = True
Else
newerFileExists = False
End If
Else
newerFileExists = False
End If
End Function