2

複数のファイルからメタデータにアクセスしようとしています。メタデータを取得するために見つけたコードはすでにありますが、異なるフォルダー内の複数のファイルから取得できる必要があります。ファイルの種類はすべて同じです。これは可能ですか?もしそうなら、それを現在のコードに追加できますか?

最終的には、すべてのメタデータを取得して、比較のためにデータベースに送信したいと思います。

これは、1つの場所にある1つのファイルから取得するために使用したコードです。

Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.IO
Imports Shell32


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call Main()
End Sub

Sub Main()
    Dim FileName As String
    FileName = "D:\Folder\Folder1\filename.pst"
    Dim Properties As Dictionary(Of Integer, KeyValuePair(Of String, String)) = GetFileProperties(FileName)
    For Each FileProperty As KeyValuePair(Of Integer, KeyValuePair(Of String, String)) In Properties
        ListBox1.Items.Add(FileProperty.Value.Key & ": " & FileProperty.Value.Value)
    Next
End Sub

Public Function GetFileProperties(ByVal FileName As String) As Dictionary(Of Integer, KeyValuePair(Of String, String))
    Dim Shell As New Shell
    Dim Folder As Folder = Shell.[NameSpace](Path.GetDirectoryName(FileName))
    Dim File As FolderItem = Folder.ParseName(Path.GetFileName(FileName))
    Dim Properties As New Dictionary(Of Integer, KeyValuePair(Of String, String))()
    Dim Index As Integer
    Dim Keys As Integer = Folder.GetDetailsOf(File, 0).Count
    For Index = 0 To Keys - 1
        Dim CurrentKey As String = Folder.GetDetailsOf(Nothing, Index)
        Dim CurrentValue As String = Folder.GetDetailsOf(File, Index)
        If CurrentValue <> "" Then
            Properties.Add(Index, New KeyValuePair(Of String, String)(CurrentKey, CurrentValue))
        End If
    Next
    Return Properties
End Function

End Class
4

1 に答える 1

1

以下のコードが役立つかどうかを確認してください -

Imports System
Imports System.Collections.Generic
Imports System.Windows.Forms
Imports System.IO
Imports Shell32


Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Call Main()
End Sub

Sub Main()

    Dim dir As New IO.DirectoryInfo("c:\")
    Dim files As IO.FileInfo() = di.GetFiles("*.pst")
    Dim file As IO.FileInfo
    Dim FileName As String

    For Each file In files

        FileName = file.FullName

        Dim Properties As Dictionary(Of Integer, KeyValuePair(Of String, String)) = GetFileProperties(FileName)
        For Each FileProperty As KeyValuePair(Of Integer, KeyValuePair(Of String, String)) In Properties
            ListBox1.Items.Add(FileProperty.Value.Key & ": " & FileProperty.Value.Value)
        Next
    Next
End Sub

Public Function GetFileProperties(ByVal FileName As String) As Dictionary(Of Integer, KeyValuePair(Of String, String))
    Dim Shell As New Shell
    Dim Folder As Folder = Shell.[NameSpace](Path.GetDirectoryName(FileName))
    Dim File As FolderItem = Folder.ParseName(Path.GetFileName(FileName))
    Dim Properties As New Dictionary(Of Integer, KeyValuePair(Of String, String))()
    Dim Index As Integer
    Dim Keys As Integer = Folder.GetDetailsOf(File, 0).Count
    For Index = 0 To Keys - 1
        Dim CurrentKey As String = Folder.GetDetailsOf(Nothing, Index)
        Dim CurrentValue As String = Folder.GetDetailsOf(File, Index)
        If CurrentValue <> "" Then
            Properties.Add(Index, New KeyValuePair(Of String, String)(CurrentKey, CurrentValue))
        End If
    Next
    Return Properties
End Function

End Class

上記のコードは、C:\ 内のすべての .pst ファイルを検索し、プロパティを読み取ります。さまざまなフォルダーを許可するには、ディレクトリの配列を作成し、構成ファイルまたは要件に応じて他の場所からそれらを読み取る必要があります。

于 2012-10-17T19:05:31.500 に答える