Vbscript 执行中的脚本超时
我写了一个小脚本来帮助重新组织我的.mp3收藏。当我运行这个脚本时,有时它会处理数千个文件,直到遇到错误条件(通常是移动名称/路径中有一个特殊字符的文件,我没有计算在内),但它通常会带着文本退出脚本 脚本“C:\DevSpace\mp3move.vbs”上的脚本执行时间已超过。 脚本执行已终止 我不知道为什么会这样。为了找出发生这种情况的原因,我添加了几行msgbox,我发现一个msgbox会弹出,但它会很快自动关闭 下面是代码-我为论坛中没有正确获得格式而道歉Vbscript 执行中的脚本超时,vbscript,Vbscript,我写了一个小脚本来帮助重新组织我的.mp3收藏。当我运行这个脚本时,有时它会处理数千个文件,直到遇到错误条件(通常是移动名称/路径中有一个特殊字符的文件,我没有计算在内),但它通常会带着文本退出脚本 脚本“C:\DevSpace\mp3move.vbs”上的脚本执行时间已超过。 脚本执行已终止 我不知道为什么会这样。为了找出发生这种情况的原因,我添加了几行msgbox,我发现一个msgbox会弹出,但它会很快自动关闭 下面是代码-我为论坛中没有正确获得格式而道歉 'Takes all .MP3
'Takes all .MP3 files in the source dir, reads the Artist tag associated with that file
'Checks for a dir named after the artist in the destination dir
'If the folder artist/album does not exists, it will create it
'Then move the .mp3 file to the dest dir
Dim oAppShell, oFSO, oFolder, oFolderItems
Dim strPath, i
Dim sInfo
iDebug=0
sInfo = "Item Description"
strPath = "K:\_preprocess"
sDestination = "K:\Music"
Set oAppShell = CreateObject("Shell.Application")
Set oFSO = CreateObject("Scripting.FileSystemObject")
If not oFSO.FolderExists(strPath) Then
WScript.Echo "Folder " & strPath & " is inaccessble"
End If
Set oFolder = oAppShell.NameSpace(strPath)
Set oFolderItems = oFolder.Items()
sCreate = ""
sExist = ""
sMoved = ""
If (not oFolderItems is nothing) Then
if oFolderItems.Count = 0 then
Wscript.echo "no files found in this folder: " & strPath
WScript.Quit
end If
If iDebug = 1 Then
i = oFolderItems.count
WScript.Echo i
End If
For Each oItem in oFolderItems
If iDebug = 1 Then
i = i - 1
End If
If oItem.Type = "MP3 audio file (mp3)" or oItem.Type = "MP3 Format Sound (.mp3)"_
Or oItem.Type = "Windows Media Audio file" or oItem.Type = "MP3 Format Sound" then
'get artist name
sArtist = oFolder.GetDetailsOf(oItem, 20)
If iDebug = 1 Then
MsgBox oItem.name
MsgBox sArtist
End If
'if 'The Beatles' change to 'Beatles, the'
If InStr(LCase(sArtist),"the") = 1 Then
sArtist = Mid(sArtist,5) & ", the"
End If
'remove \ from band name
If InStr(sArtist,"\") > 0 Then
sArtist = Replace(sAlbum,"\","")
End If
If InStr(sArtist,"/") > 0 Then
sArtist = Replace(sAlbum,"/","")
End If
If iDebug = 1 Then
MsgBox sArtist
End If
'if folder does not exist create
'MsgBox sDestination & "\" & sArtist
If oFSO.FolderExists(sDestination & "\" & sArtist) Then
'MsgBox "EXIST"
sExist = sExist & sDestination & "\" & sArtist & " exists" & vbCrLf
Else
'MsgBox "CREATE " & sDestination & "\" & sArtist
rtn = oFSO.CreateFolder(sDestination & "\" & sArtist)
sCreate = sCreate & sDestination & "\" & sArtist & " created" & vbCrLf
End If
'get album name
sAlbum = oFolder.GetDetailsOf(oItem, 14)
'remove special characters from album name
If InStr(sAlbum,":") > 0 Then
sAlbum = Replace(sAlbum,":","")
End if
If InStr(sAlbum,"?") > 0 Then
sAlbum = Replace(sAlbum,"?","")
End If
If InStr(sAlbum,"...") > 0 Then
sAlbum = Replace(sAlbum,"...","")
End If
If InStr(sAlbum,"/") > 0 Then
sAlbum = Replace(sAlbum,"/","")
End If
If InStr(sAlbum,"\") > 0 Then
sAlbum = Replace(sAlbum,"\","")
End If
'create dir artist/album
If oFSO.FolderExists (sDestination & "\" & sArtist & "\" & sAlbum) Then
'sExist = sExist & sDestination & "\" & sArtist & sAlbum & " exists" & vbCrLf
Else
'MsgBox sDestination & "\" & sArtist & "\" & sAlbum
rtn = oFSO.CreateFolder (sDestination & "\" & sArtist & "\" & sAlbum)
'sCreate = sCreate & sDestination & "\" & sArtist & " created" & vbCrLf
End If
'move file
sSource = strPath & "\" & oItem.name & ".mp3"
sDest = sDestination & "\" & sArtist & "\" & sAlbum & "\"
If iDebug=1 Then
MsgBox sSource & vbCrLf & sDest
End If
If oFSO.FileExists (sSource) Then
oFSO.MoveFile sSource, sDest
'sMoved = sMoved & sSource & " moved to " & sDest & vbcrlf
'MsgBox smoved
Else
MsgBox sSource & " not moved"
End If
End If
If iDebug = 1
WScript.Sleep 1000
WScript.Echo i
End If
Next
If iDebug=1
WScript.Echo i
End if
'MsgBox sCreate
'MsgBox sExist
'MsgBox sMoved
End If
您应该将
WScript.Timeout
属性设置为更高的值
参见示例您应该将
WScript.Timeout
属性设置为更高的值
参见示例我的输入文件存在问题。我用来测试的一些.mp3文件的标签中有非ascii字符,这导致程序冻结我的输入文件存在问题。我用来测试的一些.mp3文件的标记中有非ascii字符,这导致程序在测试过程中冻结,我已经完成了C:\//T:0和C:\//T:99999,也就是wscript.timeout=0(也就是99999),但这些文件对这个问题没有影响。我还注意到,当这个问题发生时,我可以重新启动我的系统,然后它将正常工作,无需任何代码更改。。在它决定停止工作之前,我已经完成了C:\//T:0和C:\//T:99999以及wscript.timeout=0(也是99999),但这些都不会对这个问题产生影响。我还注意到,当这个问题发生时,我可以重新启动我的系统,然后它就可以正常工作,而不需要任何代码更改。。直到它决定再次停止工作