【问题标题】:List outlook MailBox folder hierarchy using recursion- Vbscript使用递归列出 Outlook MailBox 文件夹层次结构 - Vbscript
【发布时间】:2015-04-08 05:07:58
【问题描述】:

我在通过 Outlook 邮件文件夹进行递归时遇到问题。

Function listsubfolders(folParent)
'If folParent.Folders.count = 0 Then
'WScript.Echo folParent.name
'Else
    For Each subfolder In folParent.Folders
        tempstr = folParent.name  & ">" & listsubfolders(subfolder)
        WScript.Echo tempstr
    Next
'End If 

End Function

【问题讨论】:

  • 你有什么问题?你能说得更具体点吗?

标签: recursion vbscript outlook


【解决方案1】:

这是一个如何使用递归将所有子文件夹列出到文件夹中的示例。

Option Explicit
Dim fso,ws,RootFolder,LogFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set ws = CreateObject("WScript.Shell")
LogFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "txt"
If fso.FileExists(LogFile) Then
    fso.DeleteFile(LogFile)
End If
Set RootFolder = fso.GetFolder(Browse4Folder())
Call ListSubFolders(RootFolder)
ws.run DblQuote(LogFile)
'**********************************************************************************************
Sub ListSubFolders(Folder)
    Dim Subfolder
    Set Folder = fso.GetFolder(Folder)
    For Each Subfolder in Folder.SubFolders
        Call WriteLog(Subfolder.Path)
        Call ListSubFolders(Subfolder.Path) 'Call Recursive Sub
    Next
End Sub 
'**********************************************************************************************
Sub WriteLog(strText)
    Dim fs,ts,LogFile
    Const ForAppending = 8
    LogFile = Left(Wscript.ScriptFullName, InstrRev(Wscript.ScriptFullName, ".")) & "txt"
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set ts = fs.OpenTextFile(LogFile,ForAppending,True)
    ts.WriteLine strText
    ts.Close
End Sub
'**********************************************************************************************
Function Browse4Folder()
    Dim objShell,objFolder,Message
    Message = "Please select a folder in order to scan into it and its subfolders"
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder(0,Message,1,"c:\Programs")
    If objFolder Is Nothing Then
        Wscript.Quit
    End If
    Browse4Folder = objFolder.self.path
end Function
'**********************************************************************************************
Function DblQuote(Str)
    DblQuote = Chr(34) & Str & Chr(34)
End Function
'********************************************************************************************** 

【讨论】:

  • 在这种情况下示例代码有什么帮助?你知道为什么上面显示的源代码不起作用吗?
  • 我只是举一个与递归有关的一般例子,为此你否决了我的回复? ? ?
  • 帖子没有回答问题。没用。
猜你喜欢
  • 1970-01-01
  • 2013-11-22
  • 2017-02-04
  • 1970-01-01
  • 2014-01-25
  • 2013-02-09
  • 1970-01-01
  • 1970-01-01
  • 2018-09-25
相关资源
最近更新 更多