プロが教える店舗&オフィスのセキュリティ対策術

WinXP Pro × VB6

指定したフォルダ内で「更新日時」が最新のファイルの名前を取得するにはどのようにすればよいでしょうか?
ファイル名がランダムのため、困っています。

A 回答 (1件)

FileSystemObjectのFileオブジェクトのDateLastModifiedプロパティを参照するようにしてみてはいかがでしょう



dim fso, fol, fc, f
dim col as new Collection
Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder(フォルダーパス)
Set fc = fol.Files
for each f in fc
if f.DateLastModified > "2007/4/30" then
col.Add f.Name
end if
next
といった具合で ...
    • good
    • 1
この回答へのお礼

ありがとうございます。
参考にさせていただき、以下のようにやってみました。

Dim fso, fol, fc, f1, f2
Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder(フォルダパス)
Set fc = fol.Files
For Each f1 In fc
If IsEmpty(f2) = True Then
Set f2 = fso.GetFile(f1)
End If
If f1.DateLastModified > f2.DateLastModified Then
Set f2 = fso.GetFile(f1)
End If
Next
MsgBox f2.Name

お礼日時:2007/05/01 21:40

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!

このQ&Aを見た人はこんなQ&Aも見ています