2012-10-17 3 views
2

여러 파일에서 메타 데이터에 액세스하려고합니다. 이미 메타 데이터를 가져 오는 코드가 있지만 다른 폴더에있는 여러 파일을 가져올 수 있어야합니다. 파일 형식은 모두 동일합니다. 이것이 가능한가? 그렇다면 현재 코드에 추가 할 수 있습니까?여러 위치의 여러 파일에서 메타 데이터 가져 오기

Eventaully, 모든 메타 데이터를 가져 와서 비교를 위해 데이터베이스로 보내고 싶습니다.

이것은 내가 한 위치에 한 파일에서 얻을하는 데 사용 발견 된 코드는 다음과 같습니다

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 
+0

예에서 파일 경로는 하드 코딩되어 있습니다. List 또는 문자열 배열에서 파일을 가져 와서 반복해야합니다. –

답변

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 

위의 코드 모두를 검색합니다. pst 파일을 C : \에 저장하고 속성을 읽습니다. 다른 폴더를 허용하려면 디렉터리 배열을 만들고 필요에 따라 구성 파일이나 다른 위치에서 읽을 필요가 있습니다.

+0

감사합니다 - 도움이되는 것 같습니다! 나는 1 개의 폴더에있는 파일들로부터 필요한 데이터를 얻을 수 있었다. 이제 여러 폴더에 액세스하십시오! –

+0

가장 환영받은 친구 :) –

관련 문제