Shell32.Folder.GetDetailsOf(..,..)有哪些可用选项?

时间:2014-03-13 14:38:37

标签: c# .net shell com shell32

我已经看到使用GetDetailsOf()获取有关shell项目的详细信息的答案,但数字总是神奇的数字。

我查看了FolderItemGetDetailsOf的文档,但一无所获。 (后者中的列表并非适用于所有内容。它们不包括“描述”,“作者”,也不包括回收站删除日期...)

是否有某些方法可以返回项目的可能选项?它是否列在某处?

4 个答案:

答案 0 :(得分:10)

我意外地想到了这一点。如果您将null传递给GetDetailsOf,那么它会以列名进行响应。例如,使用cscript执行以下JScript:

var shellapp = WScript.CreateObject("Shell.Application");
var folder = shellapp.NameSpace("D:\\");
for (var j = 0; j < 0xFFFF; j++) {
    detail = folder.GetDetailsOf(null, j);
    if (!detail) {
        break;
    }
    WScript.Echo("[" + j + "] = " + detail);
}

在我的Windows 10系统上输出:

[0] = Name
[1] = Size
[2] = Item type
[3] = Date modified
[4] = Date created
[5] = Date accessed
[6] = Attributes
[7] = Offline status
[8] = Availability
[9] = Perceived type
[10] = Owner
[11] = Kind
[12] = Date taken
[13] = Contributing artists
[14] = Album
[15] = Year
[16] = Genre
[17] = Conductors
[18] = Tags
[19] = Rating
[20] = Authors
[21] = Title
[22] = Subject
[23] = Categories
[24] = Comments
[25] = Copyright
[26] = #
[27] = Length
[28] = Bit rate
[29] = Protected
[30] = Camera model
[31] = Dimensions
[32] = Camera maker
[33] = Company
[34] = File description
[35] = Program name
[36] = Duration
[37] = Is online
[38] = Is recurring
[39] = Location
[40] = Optional attendee addresses
[41] = Optional attendees
[42] = Organizer address
[43] = Organizer name
[44] = Reminder time
[45] = Required attendee addresses
[46] = Required attendees
[47] = Resources
[48] = Meeting status
[49] = Free/busy status
[50] = Total size
[51] = Account name

这与Windows 2000完全不同,详见Retrieving Extended File Properties。顺便提一下,如果您传入不同的NameSpace,那么您将获得不同的属性。在我的示例中,我询问驱动器D:上的文件可用的属性可能会有所不同,具体取决于其格式。

答案 1 :(得分:1)

在win10上还有很多标志。 基本上从Neils答案(但在Powershell中)复制的代码:

    wchar_t waCoord[20];
    wsprintf(waCoord, _T("(%i,%i)"),x , y);
    MessageBox(hWnd, waCoord, _T(" click"), MB_OK);

结果:(标题是德语翻译的,所以要小心)

function Get-FileMetaDataFlags {
    $objShell = New-Object -ComObject Shell.Application 
    $objFolder = $objShell.namespace("C:\Windows")

    for ($j = 0; $j -le 0xFFFF; $j++) {
        $detail = $objFolder.GetDetailsOf("explorer.exe", $j);
        if (!$detail) {
            continue;
        }
        Write-Host "[$j] = $detail";
    }
}

答案 2 :(得分:0)

VBA功能完成这项工作。 需要Microsoft Scripting Runtime和Microsoft Shell控件及自动化

Function Propriétés(Chemin As String, Fichier As String)
    'Chemin représente le chemin du dossier où se trouve le fichier MP3
    'Fichier représente le nom du fichier mp3 avec l'extension
    Dim Shl As New Shell32.Shell
    Dim Rep As Shell32.Folder
    Dim fich As Shell32.FolderItem

    Dim aPropName() As String, i As Integer
    Set Shl = CreateObject("Shell.Application")
    Set Rep = Shl.Namespace(Chemin)
    Set fich = Rep.Items.Item(Fichier)
    For i = 0 To 1000
        ReDim Preserve aPropName(i)
        aPropName(i) = Format(i, "000 : ") & Rep.GetDetailsOf(Null, i)
        If Len(Rep.GetDetailsOf(Null, i)) = 0 Then
            ReDim Preserve aPropName(i - 1)
            Exit For
        End If
    Next
    ' Create ouput file
    Dim Fso, MyFile
    Set Fso = CreateObject("Scripting.FileSystemObject")
    Set MyFile = Fso.CreateTextFile(Chemin & "\Prop Liste - " & Fichier & ".txt", True)
    MyFile.Write Join(aPropName, Chr(13))
    MyFile.Close
    Set Fso = Nothing
    Set MyFile = Nothing
    Propriétés = aPropName

    Set Shl = Nothing
    Set Rep = Nothing
    Set fich = Nothing
End Function

答案 3 :(得分:0)

完美,这个 Get-Metadataflags 允许我获取文件版本的索引并避免定位问题,就像在 PT-BR 中那样,它是“Versão do Arquivo”,以编程方式检索很糟糕。这让我从 Technet Get-FileMetadata (https://gallery.technet.microsoft.com/scriptcenter/Get-FileMetaData-3a7ddea7) 派生出另一个函数,并通过找到它的索引(PT-BR 为 166)我想出了这个函数,该函数将文件版本作为字符串返回:

Function Get-FileVersion
{ 
    <# 
    .SYNOPSIS 
        Get-FileVersion returns metadata version information about a single file. 

    .DESCRIPTION 
        This function will return file version (or another specific attribute based on index) information about a specific file.
        It can be used to access the information stored in the filesystem. 
        Based on: Get-FileMetadata https://gallery.technet.microsoft.com/scriptcenter/Get-FileMetaData-3a7ddea7
        and Get-FileMetadataFlags https://stackoverflow.com/questions/22382010/what-options-are-available-for-shell32-folder-getdetailsof/62279888#62279888
                
    .EXAMPLE 
        Get-FileVersion -File "c:\temp\image.jpg" 
        Get information about an image file. 
    #> 

    param([Parameter(Mandatory=$True)][string]$File = $(throw "Parameter -File is required.")) 

    $index = 166 #File version index (PT-BR) from Get-FileMetadataFlags (see description)

    if(!(Test-Path -Path $File)) 
    { 
        throw "File does not exist: $File" 
        Exit 1 
    } 

    $tmp = Get-ChildItem $File 
    $pathname = $tmp.DirectoryName 
    $filename = $tmp.Name 

    $shellobj = New-Object -ComObject Shell.Application 
    $folderobj = $shellobj.namespace($pathname) 
    $fileobj = $folderobj.parsename($filename) 
    
    if($folderobj.getDetailsOf($folderobj, $index) -and $folderobj.getDetailsOf($fileobj, $index))  
    { 
        $results = $($folderobj.getDetailsOf($fileobj, $index))
    } 
     
    $results 
} #function Get-FileVersion

干杯!