检测文件夹的内容是否已更改?

时间:2021-05-24 00:31:27

Conditions:

  • Windows 98 SE
  • Windows 98 SE

  • WMI not available
  • WMI不可用

I have code that looks like this, written using my steroidal wrapping of VBScript using MSScript.

我的代码看起来像这样,使用我使用MSScript的VBScript的甾体包装编写。

do
    a = files.collectfiles( "c:\userver", "" )
    for i = 0 to ubound( a )
        f = a(i)
        if strings.endswith( f, ".usv" ) then
            d = files.readfilee( f )
            on error resume next
            executeglobal d
            nErr = err.number
            sErr = err.description
            on error goto 0
            if nErr <> 0 then
                trace "*** Error " & nErr & ", " & sErr
            end if
            files.deletefile f
        end if
    next
    system.sleep 10
    system.cooperate
loop

There's a lot of disk activity with that call to files.collectfiles. Is there some way of detecting a change in the contents of a folder without actually scanning the folder for files?

调用files.collectfiles有很多磁盘活动。有没有办法检测文件夹内容的变化而不实际扫描文件夹的文件?

3 个解决方案

#1


Define "change in the contents of a folder".

定义“文件夹内容的更改”。

If it means that a file was added, deleted, or renamed, then the modified timestamp of the folder is updated whenever such an event occurs.

如果这意味着添加,删除或重命名了文件,则只要发生此类事件,就会更新文件夹的修改时间戳。

If you're instead wanting to know when files are modified, then you'll need to read them.

如果您想要知道何时修改文件,那么您需要阅读它们。

That said, looking at what you're trying to do (scan a folder for new .usv files, and process them and delete them), then just keeping track of the timestamp on the folder and updating it right before you call collectfiles is best (note that the correct time to log is just BEFORE calling collectfiles, otherwise you run the risk of not waking up if a file gets added during the collectfiles call or immediately afterward).

也就是说,看看你想要做什么(扫描文件夹中的新.usv文件,处理它们并删除它们),然后只需跟踪文件夹上的时间戳并在调用collectfiles之前更新它就是最好的(请注意,正确的记录时间只是在调用collectfiles之前,否则如果在collectfiles调用期间或之后立即添加文件,则存在不唤醒的风险)。

#2


There is a sample which claims to work on all versions from Win95 up to at leas WinXP. Developed under Win98 with VB5. Using the (then? provided links to the docu below) undocumented SHChangeNotify* Functions.

有一个样本声称适用于从Win95到leas WinXP的所有版本。使用VB5在Win98下开发。使用(然后提供的链接到下面的文档)未记录的SHChangeNotify *函数。

SHChangeNotifyRegister: Receive Shell Change Notifications

SHChangeNotifyRegister:接收Shell更改通知

SHChangeNotifyRegister Function SHChangeNotifyDeregister Function

SHChangeNotifyRegister函数SHChangeNotifyDeregister函数

There is another solution using ReadDirectoryChangesW here:

这里有另一个使用ReadDirectoryChangesW的解决方案:

VB6 WinAPI ReadDirectoryChangesW (check the 5th post from Yang Kok Wah)

VB6 WinAPI ReadDirectoryChangesW(查看杨角华的第5篇文章)

#3


You specifically asked for something in VB and running on win98 and I have no answer for this, but MS has a c/win32 example on how to achieve this on Windows2000+ with FindFirstChangeNotification. Another thing is that apparently "FileSystemWatcher" in .NET is not working/supported on Win98. What is my point? There maybe is no easy solution for this and you have to come up with something on your own.

你特意要求在VB中运行并在win98上运行,但我没有答案,但MS有一个关于如何在Windows2000 +上使用FindFirstChangeNotification实现此目的的c / win32示例。另一件事是,显然在.NET中“FileSystemWatcher”在Win98上不起作用/支持。我的观点是什么?对此可能没有简单的解决方案,你必须自己想出一些东西。

#1


Define "change in the contents of a folder".

定义“文件夹内容的更改”。

If it means that a file was added, deleted, or renamed, then the modified timestamp of the folder is updated whenever such an event occurs.

如果这意味着添加,删除或重命名了文件,则只要发生此类事件,就会更新文件夹的修改时间戳。

If you're instead wanting to know when files are modified, then you'll need to read them.

如果您想要知道何时修改文件,那么您需要阅读它们。

That said, looking at what you're trying to do (scan a folder for new .usv files, and process them and delete them), then just keeping track of the timestamp on the folder and updating it right before you call collectfiles is best (note that the correct time to log is just BEFORE calling collectfiles, otherwise you run the risk of not waking up if a file gets added during the collectfiles call or immediately afterward).

也就是说,看看你想要做什么(扫描文件夹中的新.usv文件,处理它们并删除它们),然后只需跟踪文件夹上的时间戳并在调用collectfiles之前更新它就是最好的(请注意,正确的记录时间只是在调用collectfiles之前,否则如果在collectfiles调用期间或之后立即添加文件,则存在不唤醒的风险)。

#2


There is a sample which claims to work on all versions from Win95 up to at leas WinXP. Developed under Win98 with VB5. Using the (then? provided links to the docu below) undocumented SHChangeNotify* Functions.

有一个样本声称适用于从Win95到leas WinXP的所有版本。使用VB5在Win98下开发。使用(然后提供的链接到下面的文档)未记录的SHChangeNotify *函数。

SHChangeNotifyRegister: Receive Shell Change Notifications

SHChangeNotifyRegister:接收Shell更改通知

SHChangeNotifyRegister Function SHChangeNotifyDeregister Function

SHChangeNotifyRegister函数SHChangeNotifyDeregister函数

There is another solution using ReadDirectoryChangesW here:

这里有另一个使用ReadDirectoryChangesW的解决方案:

VB6 WinAPI ReadDirectoryChangesW (check the 5th post from Yang Kok Wah)

VB6 WinAPI ReadDirectoryChangesW(查看杨角华的第5篇文章)

#3


You specifically asked for something in VB and running on win98 and I have no answer for this, but MS has a c/win32 example on how to achieve this on Windows2000+ with FindFirstChangeNotification. Another thing is that apparently "FileSystemWatcher" in .NET is not working/supported on Win98. What is my point? There maybe is no easy solution for this and you have to come up with something on your own.

你特意要求在VB中运行并在win98上运行,但我没有答案,但MS有一个关于如何在Windows2000 +上使用FindFirstChangeNotification实现此目的的c / win32示例。另一件事是,显然在.NET中“FileSystemWatcher”在Win98上不起作用/支持。我的观点是什么?对此可能没有简单的解决方案,你必须自己想出一些东西。