0
votes

I wrote a script which can find the .apk and import aoutomaticly in outlook.

But i have a problem. i can set 4 path folder. And the script look path folders and find the apk.

But when this script can find an .apk folders, the program finish.

This script doesn't look another path.

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"
 

For example, this script find the path .apk folder

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

And doesn't look another paths.

How to solve this problem.

Thanks for any helping.

1

1 Answers

1
votes

Do never use On Error Resume Next to control the program flow. This is stupid. Check for error predictable conditions instead of letting them fail.

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"