2011-01-25 71 views
1

我写了一个小脚本来帮助重新组织我的.mp3集合。当我运行这个脚本时,它有时会处理几千个文件,直到遇到一个错误状态(通常是一个文件的名称/路径中有一个特殊字符,我没有指出),但它通常会用文本退出脚本​​执行中的脚本超时

在脚本“C:\ DevSpace \ mp3move.vbs”上超出了脚本执行时间。 脚本执行被终止。

我不知道为什么会发生这种情况。为了弄清楚在哪里出现这种情况,我添加了几个msgbox行,并且我发现msgbox会弹出,但它会很快自动关闭。

这里是代码 - 我appoligize不在论坛

'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 

回答

0

的问题,我的输入文件存在。我用来测试的一些.mp3文件在标签中没有ascii字符,导致程序冻结

1

您应该将WScript.Timeout属性设置为一个较高的值,得到正确的格式。

见例如here

+0

在测试期间,我已经完成了C:\ // T:0和C: \ // T:99999也是wscript.timeout = 0(也是99999),但这些问题没有影响。 – ccwhite1 2011-01-25 16:25:30