似乎没有人问这个简单的问题,所以我会.
我的PowerShell脚本文件位于: C:/this-folder/that-folder/another-folder/powershell-file.ps1
如何获得返回的变量: C:/this-folder/that-folder/another-folder/
CB.*_*CB. 34
在脚本中尝试此命令:
Split-Path -parent $MyInvocation.MyCommand.Definition
Run Code Online (Sandbox Code Playgroud)
Sha*_*evy 17
在PowerShell 3.0中,您可以使用新$PSScriptRoot
变量获取它,并且$PSCommandPath
您可以获得完整的脚本路径.
MVP Keith山也有一篇很棒的文章你可能想检查:
http://rkeithhill.wordpress.com/2010/09/19/determining-scriptdir-safely/
MiF*_*vil 12
您可以使用标准 .NET 方法:
$dirName = [System.IO.Path]::GetDirectoryName("c:\temp\abc\myproj1\newdata.txt")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
24544 次 |
最近记录: |