windows - Powershell 获取 Windows 中显示的区分大小写的路径

标签 windows powershell windows-subsystem-for-linux

我正在寻找一种方法来获取我的本地路径,其中包括名称中使用的任何驼峰式大小写。主要原因是我可以使用相同的路径在 windows wsl 中进行调用。例如,在 Windows 中我可以调用一个文件作为

c:\FoO\bar.txt 
c:\Foo\Bar.txt

Windows 会将其显示为 c:\foo\bar.txt。当我尝试使用 bash 进入 WSL 时,我需要知道实际路径,因为 Linux 区分大小写。

我试过用

$PSScriptRoot
Split-path C:\FoO\Bar.txt
(get-Item c:\Foo\Bar.txt).FullName

但他们只会提供调用脚本的路径。
如何获取在 Windows 操作系统中显示的路径? 我不能只调用我需要的文件的完整路径,因为我不能保证它从根目录开始。我也不想耗尽循环进行查找。

最佳答案

您想要的是查看从 Get-Item 返回的 Target 属性。 Fullname 会返回,无论您最初输入的是什么,但 Target 实际上是一个代码属性,似乎可以获取对象的原始路径。

(get-Item c:\Foo\Bar.txt).Target

关于windows - Powershell 获取 Windows 中显示的区分大小写的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48797358/

相关文章:

c - 如何在内核模式下使用 ZwQuerySystemInformation() 获取线程 ID?

windows - 检查 Windows API 级别的 DLL

powershell - 如何在powershell中找到对象的 'sub properties'?

VSCode 中的 Powershell 终端编码

linux - 使用 NASM 获取用户输入时遇到问题

ubuntu - 错误 : module 'platform' has no attribute 'linux_distribution'

java - 如何在 Windows 中将 Solr 5.0 作为后台进程运行?

windows - 在 Windows 8 Metro App 中包含资源文件

Powershell输出新行

windows-subsystem-for-linux - 使用 NVM 在 WSL 上安装节点时权限被拒绝