$dir = "./temp"Convert-Path -LiteralPath $dir相关的 Resolve-Path cmdlet 提供了类似的功能,但它不解析基于 PowerShell 特定驱动器(使用 New-PsDrive) 到其底层本机文件系统路径.The related Resolve-Path cmdlet provides similar functionality, but it doesn't resolve paths based on PowerShell-specific drives (created with New-PsDrive) to their underlying native filesystem paths.如果路径不存在(还):If the path doesn't exist (yet):在基于 .NET Core 的 PowerShell Core 中,您可以使用新的 [IO.Path]::GetFullPath() 重载,接受指定相对路径的引用目录:$dir = "./temp"[IO.Path]::GetFullPath($dir, $PWD.ProviderPath)注意当前位置的本机文件系统路径 $PWD.ProviderPath 如何作为参考目录传递.Note how the current location's native filesystem path, $PWD.ProviderPath, is passed as the reference directory.警告:如果当前位置可能位于文件系统驱动器以外的驱动器上,请使用 (Get-Location -PSProviderFileSystem).ProviderPath 可靠地引用当前文件系统位置(目录).Caveat: If there's a chance that the current location is on a drive other than a filesystem drive, use (Get-Location -PSProvider FileSystem).ProviderPath to reliably refer to the current filesystem location (directory).在Windows PowerShell中,您可以使用[IO.Path]::Combine(),但是请注意,如果您不希望在结果路径中使用 ./ 前缀,则必须手动删除它:In Windows PowerShell, you can use [IO.Path]::Combine(), but note that you'll have to remove the ./ prefix manually if you don't want it in the resulting path:$dir = "./temp"[IO.Path]::Combine($PWD.ProviderPath, $dir -replace '^.[\\/]') 这篇关于PowerShell 如何处理“."在路径中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-01 03:47