2012-02-09 13 views
5

Yalnızca en yeni dosyanın adını ve Son Değiştirme tarihini döndürmek için bu VBScript'i nasıl değiştirebilirim? Şu anda son 24 saatte değiştirilmiş bir şey döndürüyor. Sadece en yeni dosyayı aramak istiyorum. Bunu henüz bir VBScript sihirbazı değil StackOverflow'dan ödünç aldım.En son dosya tarihini tek bir klasörde bulmak için VBScript kullanma

option explicit 
dim fileSystem, folder, file 
dim path 
path = "C:\test" 
Set fileSystem = CreateObject("Scripting.FileSystemObject") 
Set folder = fileSystem.GetFolder(path) 
for each file in folder.Files   
if file.DateLastModified > dateadd("h", -24, Now) then   
'whatever you want to do to process'   
WScript.Echo file.Name & " last modified at " & file.DateLastModified  
end if 
next 

cevap

11

buna çok yakınsın:

Option Explicit 
Dim fso, path, file, recentDate, recentFile 
Set fso = CreateObject("Scripting.FileSystemObject") 
Set recentFile = Nothing 
For Each file in fso.GetFolder("C:\Temp").Files 
    If (recentFile is Nothing) Then 
    Set recentFile = file 
    ElseIf (file.DateLastModified > recentFile.DateLastModified) Then 
    Set recentFile = file 
    End If 
Next 

If recentFile is Nothing Then 
    WScript.Echo "no recent files" 
Else 
    WScript.Echo "Recent file is " & recentFile.Name & " " & recentFile.DateLastModified 
End If 
İlgili konular