可否获取文件夹扩展信息

功能建议 · 17 次浏览
沉没的白鲸 创建于 6天19小时前

测试选了一个文件夹,调试记录: 

https://temp.getquicker.net/59771/c9dbc6b2245f4c81bf456dcb72dab16b.html 

发现【检查路径/获取文件信息】得不到文件夹的扩展信息。

从资源管理器里面可以看到文件夹也有一些属性,所以我想是否有办法增加这个功能,虽然可能用处不大。

 


回复内容
CL 6天7小时前
#1

看了一下,似乎没有什么有用的信息:

{
    "ItemFolderNameDisplay": "D:\\",
    "ItemFolderNameDisplay_FriendlyName": "文件夹名称",
    "ItemTypeText": "文件夹",
    "ItemTypeText_FriendlyName": "类型",
    "ItemNameDisplay": "Work",
    "ItemNameDisplay_FriendlyName": "名称",
    "Size": "",
    "Size_FriendlyName": "大小",
    "FileAttributes": 48,
    "FileAttributes_FriendlyName": "属性",
    "DateModified": "2025-04-13T09:47:18.8211741+08:00",
    "DateModified_FriendlyName": "修改日期",
    "DateCreated": "2022-10-28T09:56:52+08:00",
    "DateCreated_FriendlyName": "创建日期",
    "DateAccessed": "2025-04-19T22:07:56+08:00",
    "DateAccessed_FriendlyName": "访问日期",
    "ItemNameDisplayWithoutExtension": "Work",
    "ItemNameDisplayWithoutExtension_FriendlyName": null,
    "FolderNameDisplay": "Work",
    "FolderNameDisplay_FriendlyName": null,
    "Document.DateCreated": "2022-10-28T09:56:52+08:00",
    "Document.DateCreated_FriendlyName": "创建内容的时间",
    "Document.DateSaved": "2025-04-13T09:47:18.8211741+08:00",
    "Document.DateSaved_FriendlyName": "最后一次保存的日期",
    "FileOwner": "dddd\\xxxxxx",
    "FileOwner_FriendlyName": "所有者",
    "NetworkLocation": "",
    "NetworkLocation_FriendlyName": "网络位置",
    "ComputerName": "dddd",
    "ComputerName_FriendlyName": "计算机",
    "ItemPathDisplayNarrow": "Work (D:)",
    "ItemPathDisplayNarrow_FriendlyName": "路径",
    "PerceivedType": 0,
    "PerceivedType_FriendlyName": "假设的类型",
    "ItemType": "Directory",
    "ItemType_FriendlyName": "项目类型",
    "ParsingName": "Work",
    "ParsingName_FriendlyName": null,
    "SFGAOFlags": 1887437183,
    "SFGAOFlags_FriendlyName": null,
    "ParsingPath": "D:\\Work",
    "ParsingPath_FriendlyName": null,
    "FileExtension": "",
    "FileExtension_FriendlyName": "文件扩展名",
    "ItemDate": "2022-10-28T09:56:52+08:00",
    "ItemDate_FriendlyName": "日期",
    "KindText": "文件夹",
    "KindText_FriendlyName": null,
    "FileAttributesDisplay": "",
    "FileAttributesDisplay_FriendlyName": null,
    "IsShared": false,
    "IsShared_FriendlyName": "已共享",
    "SharedWith": "",
    "SharedWith_FriendlyName": "共享设备",
    "SharingStatus": 0,
    "SharingStatus_FriendlyName": "共享状态",
    "ShareScope": "",
    "ShareScope_FriendlyName": null,
    "Security.EncryptionOwnersDisplay": "",
    "Security.EncryptionOwnersDisplay_FriendlyName": "文件所有权",
    "ItemName": "Work",
    "ItemName_FriendlyName": null,
    "Shell.SFGAOFlagsStrings": [
        "filesys",
        "fileanc",
        "storageanc",
        "folder"
    ],
    "Shell.SFGAOFlagsStrings_FriendlyName": null,
    "Link.TargetSFGAOFlagsStrings": "",
    "Link.TargetSFGAOFlagsStrings_FriendlyName": null,
    "OfflineAvailability": "",
    "OfflineAvailability_FriendlyName": "可用性",
    "ZoneIdentifier": 0,
    "ZoneIdentifier_FriendlyName": null,
    "LastWriterPackageFamilyName": "",
    "LastWriterPackageFamilyName_FriendlyName": null,
    "AppZoneIdentifier": "",
    "AppZoneIdentifier_FriendlyName": null,
    "Kind": [
        "folder"
    ],
    "Kind_FriendlyName": "种类",
    "Security.EncryptionOwners": "",
    "Security.EncryptionOwners_FriendlyName": null,
    "ItemFolderPathDisplayNarrow": "D:\\",
    "ItemFolderPathDisplayNarrow_FriendlyName": "文件夹",
    "FileName": "Work",
    "FileName_FriendlyName": "文件名",
    "Security.AllowedEnterpriseDataProtectionIdentities": [
        ""
    ],
    "Security.AllowedEnterpriseDataProtectionIdentities_FriendlyName": null,
    "ThumbnailCacheId": 7223901912990410265,
    "ThumbnailCacheId_FriendlyName": null,
    "VolumeId": "",
    "VolumeId_FriendlyName": null,
    "Link.TargetParsingPath": "",
    "Link.TargetParsingPath_FriendlyName": "链接目标",
    "Link.TargetSFGAOFlags": "",
    "Link.TargetSFGAOFlags_FriendlyName": null,
    "ItemFolderPathDisplay": "D:\\",
    "ItemFolderPathDisplay_FriendlyName": "文件位置",
    "ItemPathDisplay": "D:\\Work",
    "ItemPathDisplay_FriendlyName": "路径",
    "unnamed-[96]": "Work",
    "unnamed-[96]_FriendlyName": null,
    "AppUserModel.ID": "",
    "AppUserModel.ID_FriendlyName": "AppUserModelId",
    "AppUserModel.ParentID": "",
    "AppUserModel.ParentID_FriendlyName": "父 ID",
    "Link.TargetExtension": "",
    "Link.TargetExtension_FriendlyName": null,
    "OfflineStatus": "",
    "OfflineStatus_FriendlyName": "脱机状态",
    "IsFolder": false,
    "IsFolder_FriendlyName": null,
    "NotUserContent": false,
    "NotUserContent_FriendlyName": null,
    "StorageProviderAggregatedCustomStates": "",
    "StorageProviderAggregatedCustomStates_FriendlyName": "活动",
    "SyncTransferStatusFlags": "",
    "SyncTransferStatusFlags_FriendlyName": null,
    "DateImported": "2022-10-28T09:56:52+08:00",
    "DateImported_FriendlyName": "导入日期",
    "ExpandoProperties": "",
    "ExpandoProperties_FriendlyName": null,
    "FilePlaceholderStatus": 6,
    "FilePlaceholderStatus_FriendlyName": null
}
CL 最后更新于 6天7小时前
沉没的白鲸 回复 CL 5天12小时前 :

举例"KindText"或 "Kind"  稍微有点作用, 结果可能是 文件夹、音乐、视频、“未指定”等,如果不存在则输出“路径无效”,也就是说在不严格区分后缀的场景可以用一个变量就可以大致的筛选 路径存在与否 、文件或文件夹 、分类。

$$
$path = '{path}'  #  要查询的路径ps脚本示例

# 创建 Shell COM 对象
$shell = New-Object -ComObject Shell.Application

# 判断路径是文件还是文件夹
if (Test-Path -LiteralPath $path -PathType Container) {
    # 如果是文件夹
    $folder = $shell.Namespace($path)
    $folderItem = $folder.Self
    $kindText = $folder.GetDetailsOf($folderItem, 2)  # 2 是类型字段索引,通常用于获取文件夹类型
    Write-Output "$kindText"
}
elseif (Test-Path -LiteralPath $path -PathType Leaf) {
    # 如果是文件
    $folder = $shell.Namespace((Get-Item $path).DirectoryName)
    $item = $folder.ParseName((Get-Item $path).Name)
    $kindText = $folder.GetDetailsOf($item, 11)  # 9 是文件类型字段索引,通常用于获取文件类型  【假设的类型】9音频、图像,【种类】11 音乐、图片
    Write-Output "$kindText"
}
else {
    Write-Output "路径无效"
}

回复主贴