programing

PowerShell의 PowerShell 파일 폴더 경로

subpage 2023. 8. 22. 22:09
반응형

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

반응형