Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Extended File Attributes

237 views
Skip to first unread message

Richard Mueller

unread,
Nov 6, 2006, 12:38:01 AM11/6/06
to
I'm trying to retrieve an extended file attribute of a selected file in VB6.
The following fails:
=============
Dim objShell As Object
Dim objFolder As Object
Dim objFolderItem As Object

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace("c:\MyFolder")
Set objFolderItem = objFolder.ParseName("c:\MyFolder\MyApp.exe")
strComment = objFolder.GetDetailsOf(objFolderItem, 14)
============
The above assigns "Comments" to the variable strComment, the name of the
attribute rather than the value. However, if I list all FolderItems in the
Folder, I can retrieve the value of this attribute for all items in the
folder as follows:
============
For Each objFolderItem In objFolder.Items
Call MsgBox("Item: " & objFolderItem.Name _
& vbCrLf & "Comment: " & objFolder.GetDetailsOf(objFolderItem, 14))
Next
==========
If I add a reference to "Microsoft Shell Controls and Automation"
(shell32.dll), I can try the following, but it yields the same result as the
first snippet:
===========
Dim objShell As Shell
Dim objFolder As Folder2
Dim objFolderItem As FolderItem

Set objShell = New Shell
Set objFolder = objShell.Namespace("c:\MyFolder")
Set objFolderItem = objFolder.ParseName("c:\MyFolder\MyApp.exe")
strComment = objFolder.GetDetailsOf(objFolderItem, 14)
================
Is there any way to retrieve the value of the extended attribute without
enumerating every file in the folder? What's odd is that it works in
VBScript.

A link to VBScript documentation:
http://www.microsoft.com/technet/scriptcenter/guide/sas_fil_lunl.mspx?mfr=true

Other links:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/objects/folder/parsename.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_basics/shell_basics_programming/objectmap.asp
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net


Larry Serflaten

unread,
Nov 6, 2006, 9:32:05 AM11/6/06
to

"Richard Mueller" <rlmuelle...@ameritech.NOSPAM.net> wrote

> I'm trying to retrieve an extended file attribute of a selected file in VB6.
> The following fails:

I used your code and made this:

Dim objShell As Object
Dim objFolder As Object
Dim objFolderItem As Object

Dim strComment As String, i As Long

Set objShell = CreateObject("Shell.Application")

Set objFolder = objShell.Namespace("D:\temp")
Set objFolderItem = objFolder.ParseName("data.txt")

For i = 0 To 20
strComment = objFolder.GetDetailsOf(objFolderItem, i)
Debug.Print i, strComment
Next


The output I got showed the comment was actually at index 5:

0 Data.txt
1 1 KB
2 Text Document
3 11/6/2006 8:25 AM
4 A
5 COMMENT_TEXT
6 9/19/2006 12:30 PM
7 11/6/2006 8:25 AM
8 Administrators
9
10 AUTHOR_TEXT
11 TITLE_TEXT
12 SUBJECT_TEXT
13 CATEGORY_TEXT
14
15
16
17
18
19
20


I'm running Win2K SP4....

LFS


Richard Mueller

unread,
Nov 6, 2006, 11:35:17 AM11/6/06
to

Thanks for the reply. The good news is that you showed me I need to pass
just the filename to the ParseName method (not the full path and file name).
The bad news is that you also pointed out that the index values change
depending on the OS. On XP clients, the comment has index 14. Index 5 is
date accessed. I confirmed that on a W2k machine the comment is index 5.
This of course makes my code useless. The only fix I see is to enumerate all
extended attributes until I find the one with the name "Comments" (or
whichever I want). At least now I don't have to enumerate all items in the
folder.

Larry Serflaten

unread,
Nov 6, 2006, 12:27:40 PM11/6/06
to

"Richard Mueller" <rlmuelle...@ameritech.NOSPAM.net> wrote

> The only fix I see is to enumerate all
> extended attributes until I find the one with the name "Comments" (or
> whichever I want). At least now I don't have to enumerate all items in the
> folder.


Depending on what you want to get, you might be able to parse what
you want out of the file tip information:

msgbox GetFileTipInfo("D:\temp", "data.txt")

Private Function GetFileTipInfo(Path As Variant, File As Variant) As String
Dim shl As Object, fld As Object, itm As Object
Set shl = CreateObject("Shell.Application")
If Not shl Is Nothing Then
Set fld = shl.NameSpace(Path)
If Not fld Is Nothing Then
Set itm = fld.ParseName(File)
If Not itm Is Nothing Then
GetFileTipInfo = fld.GetDetailsOf(itm, -1)
End If
End If
End If
End Function


LFS


Richard Mueller

unread,
Nov 6, 2006, 10:07:59 PM11/6/06
to

"Larry Serflaten" <serf...@usinternet.com> wrote in message
news:uYeWeicA...@TK2MSFTNGP03.phx.gbl...

Thanks for the code. I have not seen that documented.

Larry Serflaten

unread,
Nov 7, 2006, 12:32:26 PM11/7/06
to

"Richard Mueller" <rlmuelle...@ameritech.NOSPAM.net> wrote


> Thanks for the code. I have not seen that documented.

Its the last item in the list of parameters (iColumn):
http://msdn.microsoft.com/library/en-us/shellcc/platform/shell/reference/objects/folder/getdetailsof.asp

LFS


0 new messages