假设我有一个名为“C:\”的文件夹,在这个文件夹中有许多名称如“0001”,“0002”,“0003”等的.txt文件。我怎么去获取文件名最后修改/编辑过的文件到变量?
我正在使用Visual Basic 6.
干杯
答案 0 :(得分:1)
最好在VB6中使用FileSystemObject您必须引用它。转到项目>引用。查找并检查“Microsoft Scripting Runtime”
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Dim strPath As String
Dim strLastFile As String
Dim dCompareDate As Date
strPath = "C:\"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
dCompareDate = CDate("1/1/1900")
For Each objFile In objFolder.Files
If objFile.DateLastModified > dCompareDate Then
dCompareDate = objFile.DateLastModified
strLastFile = objFile.Name
End If
Next
Debug.Print strLastFile