gpt4 book ai didi

vbscript - 如何在删除文件夹时暂停 VBS 脚本?

转载 作者:行者123 更新时间:2023-12-02 22:43:21 25 4
gpt4 key购买 nike

我正在为 SyncBack(备份实用程序)编写一个 VBScript,在其中删除旧版本的备份。

    '' # if current version is greater than the total allowed number of versions,
'' # delete the oldest folder
If versionNumber > totalVersions Then
delDirNum = versionNumber - totalVersions
If delDirNum > 0 Then
DelFoldername = containerFileOrFolder & "\" & delDirNum & "_"
'' " # Ignore this line SO Prettify doesn't do VB very well.
If fso.FolderExists(DelFoldername) = True Then
WScript.Echo "Deleting: <" & DelFoldername & ">"
Set oFolder = objFileSystem.GetFolder(DelFoldername)
oFolder.Delete()
WScript.Sleep 2000
If fso.FolderExists(DelFoldername) = False Then
WScript.Echo "Deleted <" & DelFoldername & "> successfully"
Else
WScript.Echo "Could not delete <" & DelFoldername & ">"
End If
End If
End If
End If

但是,有时我尝试删除的文件夹(包含旧备份)需要比 WScript.Sleep 2000 的 2 秒更长的时间才能删除,我想知道是否有办法让脚本等到文件夹被删除后才打印出“已成功删除 ”。

理想情况下,我喜欢这样的东西:

While oFolder.IsDeleting() Then
WScript.Echo "Still deleting..."
WScript.Sleep 2000
Loop

但我很清楚情况可能并非如此。

最佳答案

While fso.FolderExists(DelFoldername)
WScript.Echo "Still deleting"
WScript.Sleep 1000
Wend

关于vbscript - 如何在删除文件夹时暂停 VBS 脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1770267/

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