Home > Mobile >  Get localized file (resource) names, as shown in Windows Explorer
Get localized file (resource) names, as shown in Windows Explorer

Time:06-22

I am looking for a PowerShell function like Get-LocalizedName($FilePath), returning the localized name of a file or its filename if it is not localized. I know that the localized names are stored in the LocalizedFileNames section of the respective desktop.ini files, but usually as resource file pointers rather than clear names.

Example: For the Administrative Tools folder and the locale de-DE, I want the clear name Windows-Verwaltungsprogramme instead of @%SystemRoot%\system32\shell32.dll,-21762.

I was not able to find such a function, and also was not successful in analyzing the attributes of Get-ChildItem or google a regarding solution.

Is there any such function that I could use from PowerShell (v7)?

CodePudding user response:

The following solution works for folders only. See this answer for a solution that works for files, localized via LocalizedFileNames section of Desktop.ini.


This can be done using the Shell.Application COM object:

$shell = New-Object -ComObject Shell.Application

# Get full path to the admin tools folder
$adminToolsPath = [Environment]::GetFolderPath('AdminTools')

# Get the shell folder corresponding to this path
if( $folder = $shell.NameSpace( $adminToolsPath ) ) {
    $folder.Title  # Output localized title
}

# Alternative:
if( $folder = $shell.NameSpace( [Environment SpecialFolder]::AdminTools ) ) {
    $folder.Title  # Output localized title
}
  • [Environment]::GetFolderPath() gives us the filesystem path of a system folder.
  • The Shell.Namespace() function returns a Folder object corresponding to this path which can be queried for its localized name.
  • The alternative shows how you can get the localized name more directly, by passing an enumeration value of [Environment SpecialFolder] to the Shell.Namespace() function.
  • When passing a path to the Shell.Namespace() method, it works for any folder customized via "desktop.ini", even if it's not a system folder.

CodePudding user response:

I finally found a solution for Get-LocalizedName, digging into 20 years old VBS code using GetDetailsOf:

function Get-LocalizedName {
    Param([Parameter(Mandatory=$True)][string]$FilePath) 
    $ChildObj = Get-ChildItem $FilePath 
    $FldrName = $ChildObj.DirectoryName 
    $FileName = $ChildObj.Name 
    $Shell    = New-Object -ComObject Shell.Application 
    $Folder   = $Shell.Namespace($FldrName) 
    $File     = $Folder.ParseName($FileName) 
    return $($Folder.GetDetailsOf($File,0))
}
  • Related