1

i want to make a Visual basic script console app that prints edited if a file has been modified. for example if i have a text file with some notes in and i add it to a folder when its edited the program checks the folder its in and the files then prints the name of the file and modified or not modified how would i go about doing this i am relatively new to Visual basic script i probably have 4 months basic experience.

    console.writeline("what do i do?")
    console.writeline("and how do i do it")

and I'm trying to do it as a console app so the preferred outcome i would like to see would be

    File Checker
    test.txt - Edited
    test2.pptx - Un-edited
    etc etc etc
4

1 回答 1

2

如果您需要立即通知,WMI 可能是最佳途径。但是 WMI 还要求您的进程始终处于运行状态(处于阻塞状态)。或者,您可以安排一个 VBScript 以某个时间间隔启动,它可以根据您用于存储上次运行脚本的修改日期的文本文件或数据库检查每个文件的最后修改日期。

一个更简单的解决方案是检查自上次运行以来修改时间是否发生了变化。例如,如果您的脚本每 10 分钟运行一次,并且您发现一个文件在过去 10 分钟内发生了更改,请报告它。

With CreateObject("Scripting.FileSystemObject")
    For Each File In .GetFolder("c:\folder").Files
        If DateDiff("n", File.DateLastModified, Now) < 10 Then
            ' File has been modified in past 10 minutes.
        End If
    Next
End With
于 2014-02-15T16:51:30.970 回答