2011-01-25 2 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

+0

Я также заметил, что когда эта проблема возникает, я могу перезагрузить свою систему, и тогда она будет работать правильно без каких-либо изменений кода .. пока она не решит перестать работать снова – ccwhite1

Смежные вопросы