반응형
PowerShell의 PowerShell 파일 폴더 경로
내 PowerShell 스크립트 파일은 다음 위치에 있습니다.C:/this-folder/that-folder/another-folder/powershell-file.ps1
.
반환되는 변수를 가져오려면 어떻게 합니까?C:/this-folder/that-folder/another-folder/
?
스크립트에서 다음 명령을 사용해 보십시오.
Split-Path -parent $MyInvocation.MyCommand.Definition
PowerShell 3.0에서는 새로운 기능과 함께$PSScriptRoot
변수 및 포함$PSCommandPath
전체 스크립트 경로를 얻을 수 있습니다.
MVP 키스 힐의 멋진 게시물도 확인하고 싶을 것입니다.안전하게 $ScriptDir 결정
표준을 사용할 수 있습니다.NET 방법:
$dirName = [System.IO.Path]::GetDirectoryName("c:\temp\abc\myproj1\newdata.txt")
PowerShell에서: 파일 또는 디렉터리 경로에서 상위 디렉터리 이름을 가져옵니다.
스크립트가 실행될 때 어떤 폴더에서 스크립트가 실행되고 있는지 알고 싶어하는 것 같습니다.
이렇게 하면 됩니다.
Split-Path $MyInvocation.MyCommand.Path
언급URL : https://stackoverflow.com/questions/9063964/folder-path-of-a-powershell-file-in-powershell
반응형
'programing' 카테고리의 다른 글
응답 다운로드JS 개체(파일) (0) | 2023.08.22 |
---|---|
NodeJs 및 MariaDB, 사용자 및 암호 저장 (0) | 2023.08.22 |
iOS 기기만을 대상으로 하는 CSS 미디어 쿼리 (0) | 2023.08.22 |
파이썬을 사용하여 Ajax 페이지 스크랩 (0) | 2023.08.17 |
"error: cannot locate the Oracle software installation" cx_Oracle을 설치하려고 할 때 (0) | 2023.08.17 |