Reputation: 197
I am automatically obtaining directories from an application but I can't seem to get the actual directories with the correct case of letters.
For example I get $a='C:\test\dir\log\wqerst'
but the actual directory is C:\test\dir\log\WQERST
.
What I want is to uppercase only wqerst
so it would show C:\test\dir\log\WQERST
I've already tried using substring
but I don't know how I would be able to connect it to the whole directory once it is uppercase.
Upvotes: 2
Views: 3519
Reputation: 17462
Windows system is not case sensitive, but if you want really this result, you can do it :
$a='C:\test\dir\log\wqerst'
$parentpath=Split-Path -Path $a
$file=(Split-Path -Path $a -Leaf).ToUpper()
$result=Join-Path $parentpath $file
$result
Upvotes: 2
Reputation: 58931
As James C. and vonPryz already wrote, there is not much point to get the case sensitive folder path. However you can use this helper method:
function Get-CaseSensitiveFilePath
{
Param
(
[string]$FilePath
)
$parent = Split-Path $FilePath
$leaf = Split-Path -Leaf $FilePath
$result = Get-ChildItem $parent | where { $_ -like $leaf }
$result.FullName
}
usage:
Get-CaseSensitiveFilePath -FilePath 'C:\test\dir\log\WQERST'
This will give you the case sensitive folder name but the directory must exist on the computer you execute the script...
Upvotes: 1