此脚本可以正常工作(即使有20多个论坛都表示无法完成此脚本,因此也许会对其他人有所帮助。
它检查文件夹中的最新文件,并在弹出窗口中给我日期。
我希望它检查文件并将其保存为.txt文件
`Option Explicit
Dim fso, path, file, recentDate, recentFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("c:\check").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 report has been run before"
Else
WScript.Echo "This report was last run at " & " " &
recentFile.DateLastModified
End If
它另存为.vbs
答案 0 :(得分:0)
如果我理解正确,则文件位于.vbs中,并且您希望将其另存为.txt。这是这样做的方法。
我不知道你是不是想通过检查。
Option Explicit
Dim fso, path, file, recentDate, recentFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("c:\check").Files
If (recentFile is Nothing) Then
Set recentFile = file
ElseIf (file.DateLastModified > recentFile.DateLastModified) Then
Set recentFile = file
End If
'replace extension in full path - not case sensitive
file_name_txt = Replace(File.Path, ".vbs", ".txt", 1, -1, vbTextCompare)
'Warning - moving the file will delete the source
file.move file_name_txt
'You may also use file.copy to keep the original
'file.copy file_name_txt, True '(overwrite)
Next
If recentFile is Nothing Then
WScript.Echo "No report has been run before"
Else
WScript.Echo "This report was last run at " & recentFile.DateLastModified
End If