gpt4 book ai didi

vbscript - 从vbs中具有特定扩展名的文件夹中获取最后修改的文件

转载 作者:行者123 更新时间:2023-12-02 07:02:39 24 4
gpt4 key购买 nike

我有以下代码,我需要的是找到扩展名为 PNG 和最近的最后修改日期的文件,我能够找到最后修改日期,但是如果我将扩展名检查放在文件上,它会出错[对象需要在第[一些数字]行的'recentFile']

脚本

For Each objFile in colFiles
' Finds the latest modified file in folder
if (recentFile is nothing) then
Set recentFile = objFile
elseif (objFile.DateLastModified > recentFile.DateLastModified) then
Set recentFile = objFile
end if
Next

我知道我可以稍后检查扩展名,但问题是如果有一个最新的文件而不是 PNG 怎么办?虽然有些文件带有 PNG 扩展名,但与其他文件相比不是最新的,所以我只需要为 PNG 文件找到最后修改日期为最新的 PNG,请帮助我如何实现它?

最佳答案

首先过滤扩展名:

  Dim oLstPng : Set oLstPng = Nothing
Dim oFile
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
For Each oFile In goFS.GetFolder("..\testdata\17806396").Files
If "png" = LCase(goFS.GetExtensionName(oFile.Name)) Then
If oLstPng Is Nothing Then
Set oLstPng = oFile ' the first could be the last
Else
If oLstPng.DateLastModified < oFile.DateLastModified Then
Set oLstPng = oFile
End If
End If
End If
Next
If oLstPng Is Nothing Then
WScript.Echo "no .png found"
Else
WScript.Echo "found", oLstPng.Name, oLstPng.DateLastModified
End If

(看看here)

关于vbscript - 从vbs中具有特定扩展名的文件夹中获取最后修改的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17806396/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com