gpt4 book ai didi

powershell - 如何从Powershell中包含完全限定文件名的变量中仅获取目录名称?

转载 作者:行者123 更新时间:2023-12-03 01:21:19 25 4
gpt4 key购买 nike

在powershell中,此变量是配置文件的路径:$Profile
在我的系统上,它等于:

  C:\Users\Warren\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1

我只想得到路径部分:
  C:\Users\Warren\Documents\WindowsPowerShell\

在C#中,您会调用 Path.GetDirectoryName,所以我想我可以调用 [system.io.Path]::GetDirectoryName($fileName),但是我想知道在PowerShell中是否应该了解内置的路径操作系统?

这是人们的工作吗?
   [system.io.Path]::GetDirectoryName($Profile)

最佳答案

使用Split-Path cmdlet:

Split-Path $PROFILE -Parent

关于powershell - 如何从Powershell中包含完全限定文件名的变量中仅获取目录名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13367853/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com