GetDetailsOf 可以取得檔案資訊,
但發現之前寫的代碼(如 #1A0ppV_c 9523 )到WIN7不能用了,
原來是數字代表的東西改了,
提醒有用到的人 ^^。
原以為不能用時
看到這篇用vista也可,才發現可以
http://gcrlin.blogspot.com/2009/06/shellnamespace.html
------
Excel VBA Comics
crdotlin 的學習經驗分享園地
使用Shell.NameSpace方法取得檔案的詳細資訊
NameSpace方法請參閱Microsoft MSDN說明:
http://msdn2.microsoft.com/en-us/library/bb774085(VS.85).aspx
NameSpace方法可以用在取得資料夾各方面的資訊,在這裡我們嘗試列舉所選定檔案的所
有資訊。
當然,檔案資訊可以其他方法獲取,例如Microsoft Scripting Runtime的
FileSystemObject物件。但是,試試NameSpace也是很福氣啦!
'NameSpace方法請參考
http://msdn2.microsoft.com/en-us/library/bb774085(VS.85).aspx
'請設定引用項目Microsoft Shell Controls and Automation
'如此才可以宣告FolderItem, Folder, Shell等變數
Option Explicit
'列舉選定檔案的詳細資訊
Sub getDetailsOfFile()
Dim myShl As New Shell
Dim curFolder As Folder
Dim theItm As FolderItem
Dim Fn As Variant
Dim theTitle As String
Dim outStr As String
Dim i As Long
'使用Application.GetOpenFilename 方法來指定檔案
Fn = Application.GetOpenFilename
'若點選 [取消],則退出
If Fn = "False" Then Exit Sub
'設定該檔案的目錄物件
Set curFolder = myShl.Namespace(CurDir)
'摘取檔名
Fn = Split(Fn, "\"): Fn = Fn(UBound(Fn))
'對此目錄
With curFolder
'取得第一個檔案資訊的標題
theTitle = .GetDetailsOf(0, i)
Do While theTitle <> "" '有標題
'若拿掉此測試的話,將可看到所有欄位
If .GetDetailsOf(.Items.Item(Fn), i) <> "" Then '有資訊的話
'將標題與資訊串接在輸出字串outStr
outStr = outStr & theTitle & ": " & vbTab &
.GetDetailsOf(.Items.Item(Fn), i) & vbCrLf
End If
'下一項目
i = i + 1
'取得標題
theTitle = .GetDetailsOf(0, i)
Loop
End With
'釋放物件
Set myShl = Nothing
'輸出結果
MsgBox outStr
End Sub
我的作業環境:Vista, Office 2007
getFileInfos.xls
http://www.box.net/shared/xvvqddb4gw
第二下載區
getFileInfos.xls
http://sites.google.com/site/crdotlin/Home/200906/getFileInfos.xls
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.47.1.103
※ 編輯: JieJuen 來自: 114.47.1.103 (03/13 18:50)