Script Hanging?
"Martin" <xbo61@dial.pipex.com> skrev i melding
news:079501c3630f$90d7b1e0$a601280a@phx.gbl...
****** Script begins here ********
A similar thing happends to me. don't know why, but it seems that under
certain cir***stances the script just stops running. In my example, my
script was trying to delete some files, and create a logg for those files
(if any) that failed to be deleted. Well, instead of waste my time
explaining the script problem, i rather just paste it into here:
' Delete all files in folder "TestFolder"
' While it deletes Files in the folder, it Write to a log-file
' the date and time. After that, the log-file get some more lines at the end
' listing up files that was successfully deleted, and those one
' that couldn't be deleted.
Dim EachFileToDelete
Set FileSystemObject = CreateObject("Scripting.FileSystemObject")
Set Test_FolderObj = FileSystemObject.getFolder("G:\TestFolder")
Set ParentFolderToThisFile =
FileSystemObject.getFile(WScript.ScriptFullName).P arentFolder
Set FilesCollectionToBeDeleted = Test_FolderObj.files
' Create a text-stream file, the log-file.
Set logg = FileSystemObject.OpenTextFile(ParentFolderToThisFi le.path &
"\Logfile.log", 8, True)
MuSub
' cal the sub-procedure
Sub MuSub()
On Error Resume Next
If FilesCollectionToBeDeleted.count > 0 Then ' Antall filer > 0.
logg.writeLine Date & VbTab & Time & VbTab & "Number of sucessed file
deletes: " & FilesCollectionToBeDeleted.count
Else
logg.writeLine Date & VbTab & Time & VbTab & "No files to delete"
End If
err.clear
For each EachFileToDelete in FilesCollectionToBeDeleted
FileSystemObject.deleteFile(EachFileToDelete)
MsgBox "Test: Te code runs so far"
' Error. That message never comes up.
If err.number <> 0 Then ' File couldn't be deleted for some reason.
'MsgBox "Was not alowed to delete te file named " & EachFileToDelete.name
logg.writeLine " The following file wasn't deleted: " &
EachFileToDelete.name
Else
'MsgBox "File deleted " & EachFileToDelete.name
logg.writeLine " -- " & EachFileToDelete.name
End If
err.clear
Next
End Sub
***** End script ********
Of couse, my announcement of my own problem will probably not help you, but
now we have a common type of problem. It has to be an error in windows
scripting host, if i'm not blinded to see my own errors, but i couldn't find
anyone. Hope there is a solution.
|