I'm writing a VBScript for SyncBack (backup utility) in which I am deleting old versions of a backup.
'' # 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
However, occasionally the folder (that contains the old backup) which I am trying to delete takes longer that the 2 seconds at WScript.Sleep 2000 to remove and I was wondering if there was a way of making the script wait until the folder has been deleted before it prints out "Deleted <foldername> successfully".
Ideally I'd love something like:
While oFolder.IsDeleting() Then
WScript.Echo "Still deleting..."
WScript.Sleep 2000
Loop
But I'm well aware that that's probably not going to be the case.
While fso.FolderExists(DelFoldername)
WScript.Echo "Still deleting"
WScript.Sleep 1000
Wend
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With