2011-09-19 62 views
0

我寫了一個腳本,可以找到.apk並在outlook中直接導入。Vbscript查找.apk和導入前景

但我有一個問題。我可以設置4路徑文件夾。腳本查看路徑文件夾並找到apk。

但是當這個腳本可以找到.apk文件夾時,程序就結束了。

此腳本看起來不是另一條路徑。

 
On Error Resume Next 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objnet = CreateObject("wscript.network") 
    Set olkApp = CreateObject("Outlook.Application") 
    Set objFolder = objFSO.GetFolder("C:\Documents and Settings\" & objnet.UserName & "\") 
    Set objFolder = objFSO.GetFolder("C:\Documents and Settings\" & objnet.UserName & "\Local Settings\Application Data\Microsoft\Outlook") 
    Set objFolder = objFSO.GetFolder("C:\Documents and Settings\" & objnet.UserName & "\Belgelerim\mail") 
    Set objFolder = objFSO.GetFolder("C:\Documents and Settings\" & objnet.UserName & "\AppData\Local\Microsoft\Outlook") 
    Set objFolder = objFSO.GetFolder("C:\Documents and Settings\" & objnet.UserName & "\Belgelerim\mailbox") 
    For Each objFile in objFolder 
     If LCase(objFSO.GetExtensionName(objFile.Name)) = "pst" Then 
      olkApp.Session.AddStore objFile.Path 
    End If 
Next 
MsgBox "Done" 

例如,該腳本找到路徑的.apk文件夾

 
(Set objFolder = objFSO.GetFolder("C:\Documents and Settings\" & objnet.UserName & "\"))

,不看其他的路徑。

如何解決這個問題。

感謝您的幫助。

回答

1

從來沒有使用On Error Resume Next來控制程序流程。這很愚蠢。 檢查是否有錯誤可預測的情況,而不是讓它們失敗。

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objnet = CreateObject("WScript.Network") 
Set olkApp = CreateObject("Outlook.Application") 

paths = Array(_ 
    "C:\Documents and Settings\" & objnet.UserName & "\", _ 
    "C:\Documents and Settings\" & objnet.UserName & "\Local Settings\Application Data\Microsoft\Outlook", _ 
    "C:\Documents and Settings\" & objnet.UserName & "\Belgelerim\mail", _ 
    "C:\Documents and Settings\" & objnet.UserName & "\AppData\Local\Microsoft\Outlook", _ 
    "C:\Documents and Settings\" & objnet.UserName & "\Belgelerim\mailbox" _ 
) 

For Each path In paths 
    If objFSO.FolderExists(path) Then 
     For Each objFile in objFSO.GetFolder(path).Files 
      If LCase(objFSO.GetExtensionName(objFile.Name)) = "pst" Then 
       olkApp.Session.AddStore objFile.Path 
      End If 
     Next 
    End If 
Next 

MsgBox "Done" 
+0

+1與有關領導告誡你的答案'上的錯誤恢復Next' – PaulStock

+0

@PaulStock:哈,我不得不尋找「諫言」。現在說很長一段時間的英語,但仍然在擴大我的詞彙量。 :) – Tomalak

+0

你在SO上學到各種東西,包括詞彙:) – PaulStock