0

我已经创建了我的 Visual Basic 脚本,它将从文件夹 C: 中提取所有文件并将其转换为文本文件。这仅适用于 1 个文件夹路径,我无法为两个路径创建。我的文本文件还包含文件夹 C: 中文件大小的所有文件,但我只需要文件夹 C: 中的“Outlook 项目”将其提取为文本。请看下面我的脚本;

Sub Tester()

Dim ObjOutFile

    Set ObjOutFile = CreateObject("Scripting.FileSystemObject"). _
                     CreateTextFile("D:\Users\User\Desktop\outcome.txt")

    ListFiles ObjOutFile, "D:\MOV1", "Outlook Item"
    ListFiles ObjOutFile, "D:\MOV2", "Outlook Item"

    ObjOutFile.Close

End Sub


Sub ListFiles(f, folderPath As String, fileType As String)
Dim ObjFiles, ObjFile, sz

    fileType = UCase(fileType)
    Set ObjFiles = CreateObject("Scripting.FileSystemObject") _
                                .getfolder(folderPath).Files

    For Each ObjFile In ObjFiles
        If UCase(ObjFile.Type) = fileType Then
            sz = Round(ObjFile.Size / 1024, 2)
            f.WriteLine sz & String(50 - Len(sz), " ") & ObjFile.Path
        End If
    Next

End Sub
4

1 回答 1

0
Sub Tester()

Dim ObjOutFile

    Set ObjOutFile = CreateObject("Scripting.FileSystemObject"). _
                     CreateTextFile("C:\Users\User\Desktop\outcome")

    ListFiles ObjOutFile, "C:\Users\User\Desktop\Folder A", "Outlook Item"
    ListFiles ObjOutFile, "C:\Users\User\Desktop\Folder B", "Outlook Item"

    ObjOutFile.Close

End Sub


Sub ListFiles(f, folderPath As String, fileType As String)
Dim ObjFiles, ObjFile, sz

    fileType = UCase(fileType)
    Set ObjFiles = CreateObject("Scripting.FileSystemObject") _
                                .getfolder(folderPath).Files

    For Each ObjFile In ObjFiles
        If UCase(ObjFile.Type) = fileType Then
            sz = Round(ObjFile.Size / 1024, 2)
            f.WriteLine sz & String(50 - Len(sz), " ") & ObjFile.Path
        End If
    Next

End Sub
于 2013-09-06T16:18:04.427 回答