使用VBScript在单个文件夹中查找最近的文件日期 [英] Using VBScript to find most recent file date in a single folder

查看:166
本文介绍了使用VBScript在单个文件夹中查找最近的文件日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能修改这个VBScript来只返回最新的文件名和上次修改日期?目前它返回在过去24小时内修改的任何东西。我只想查找最近的文件。我借用了这个从StackOverflow,而不是一个VBScript向导。

pre $选项显式
dim文件系统,文件夹,文件
dim path
path =C:\ test
Set fileSystem = CreateObject(Scripting.FileSystemObject)
Set folder = fileSystem.GetFolder(path)
for文件夹中的每个文件。文件
if file.DateLastModified> dateadd(h,-24,Now)然后
'无论你想要做什么来处理'
WScript.Echo file.Name& 最后修改和 file.DateLastModified
end if
next


解决方案



  Option Explicit 
Dim fso,path,file,recentDate,最新文件
设置fso = CreateObject(Scripting.FileSystemObject)
设置recentFile = Nothing
对于fso.GetFolder(C:\Temp)中的每个文件文件
如果(recentFile是Nothing)然后
Set recentFile = file
ElseIf(file.DateLastModified> recentFile.DateLastModified)然后
Set recentFile = file
End If
Next

如果recentFile是Nothing然后
WScript.Echono recent files
else
WScript.Echo最近的文件是& recentFile.Name& & recentFile.DateLastModified
End If


How could I modify this VBScript to return only the newest file's name and Last Modified date? Currently it returns anything modified in the last 24 hours. I want to look for the most recent file only. I borrowed this from StackOverflow, not yet a VBScript wizard.

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 

解决方案

you're pretty close to it:

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

这篇关于使用VBScript在单个文件夹中查找最近的文件日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆