파일 시스템용 Test-Path

업데이트 날짜: 2014년 10월

적용 대상: Windows PowerShell 2.0, Windows PowerShell 3.0, Windows PowerShell 4.0, Windows PowerShell 5.0

파일 또는 디렉터리 경로의 모든 요소가 있는지를 확인합니다.

구문

Test-Path [-NewerThan <DateTime>] [-OlderThan <DateTime>] [<CommonParameters>]

설명

파일 시스템 드라이브에서 Test-Path는 경로가 올바른지 여부, 경로의 모든 요소가 있는지 여부를 알려주거나 경로가 파일로 연결되는지 또는 디렉터리로 연결되는지를 보고할 수 있습니다. 파일이 특정 날짜 이전에 변경되었는지 또는 이후에 변경되었는지를 알려줄 수도 있습니다.

참고: 이 사용자 지정 cmdlet 도움말 파일은 파일 시스템 드라이브에서 Test-Path cmdlet이 작동하는 방식을 설명합니다. 모든 드라이브의 Test-Path cmdlet에 대한 자세한 내용을 보려면 "Get-HelpTest-Path -Path $null"을 입력하거나 Test-Path(https://go.microsoft.com/fwlink/?LinkID=113418)(영문)를 참조하세요.

매개 변수

-OlderThan <DateTime>

파일의 LastWriteTime 값이 지정된 날짜보다 작으면 "True"를 반환합니다. 그렇지 않으면 "False"를 반환합니다. Get-Date cmdlet이 반환하는 개체와 같은 DateTime 개체를 입력하거나 DateTime 개체로 변환될 수 있는 문자열(예: "August 10, 2011 2:00 PM")을 입력합니다.

OlderThan은 파일 시스템 경로에만 작동하는 동적 매개 변수입니다. Windows PowerShell 3.0에서 처음 도입되었습니다.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

-NewerThan <DateTime>

파일의 LastWriteTime 값이 지정된 날짜보다 크면 "True"를 반환합니다. 그렇지 않으면 "False"를 반환합니다. Get-Date cmdlet이 반환하는 개체와 같은 DateTime 개체를 입력하거나 DateTime 개체로 변환될 수 있는 문자열(예: "August 10, 2011 2:00 PM")을 입력합니다.

NewerThan은 파일 시스템 경로에만 작동하는 동적 매개 변수입니다. Windows PowerShell 3.0에서 처음 도입되었습니다.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

<CommonParameters>

이 cmdlet은 일반 매개 변수 -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, -OutVariable, -Verbose, -WarningAction 및 -WarningVariable을 지원합니다. 자세한 내용은 about_CommonParameters를 참조하세요.

입력 및 출력

입력 유형은 cmdlet에 파이프할 수 있는 개체의 유형입니다. 반환 유형은 cmdlet에서 반환되는 개체의 유형입니다.

입력

System.String

경로(리터럴 경로 아님)가 포함된 문자열을 Test-Path로 파이프할 수 있습니다.

출력

System.Boolean

예제 1

C:\PS>Test-Path -Path "C:\Documents and Settings\NicoleH"

Description
-----------
This command tells whether all elements in the path exist, that is, the C: directory, the Documents and Settings directory, and the NicoleH directory. If any are missing, the cmdlet returns FALSE. Otherwise, it returns TRUE.





예제 2

C:\PS>Test-Path -Path $profile

C:\PS>Test-Path -Path $profile -IsValid

Description
-----------
These commands test the path to the Windows PowerShell profile. 

The first command determines whether all elements in the path exist. The second command determines whether the syntax of the path is correct. In this case, the path is FALSE, but the syntax is correct (TRUE). These commands use $profile, the automatic variable that points to the location for the profile, even if the profile does not exist.

For more information about automatic variables, see about_Automatic_Variables.





예제 3

C:\PS>Test-Path -Path "C:\CAD\Commercial Buildings\*" -Exclude *.dwg

Description
-----------
This command tells whether there are any files in the Commercial Buildings directory other than .dwg files. 

The command uses the Path parameter to specify the path. Because it includes a space, the path is enclosed in quotes. The asterisk at the end of the path indicates the contents of the Commercial Building directory. (With long paths, like this one, type the first few letters of the path, and then use the TAB key to complete the path.)

The command uses the Exclude parameter to specify files that will be omitted from the evaluation. 

In this case, because the directory contains only .dwg files, the result is FALSE.





예제 4

C:\PS>Test-Path -Path $profile -PathType Leaf

Description
-----------
This command tells whether the path stored in the $profile variable leads to a file. In this case, because the Windows PowerShell profile is a .ps1 file, the cmdlet returns TRUE.





예제 5

C:\PS>Test-Path -Path HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell

TRUE

C:\PS> Test-Path -Path HKLM:\Software\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell\ExecutionPolicy
FALSE

Description
-----------
These commands use the Test-Path cmdlet with the Windows PowerShell registry provider. 

The first command tests whether the registry path to the Microsoft.PowerShell registry key is correct on the system. If Windows PowerShell is installed correctly, the cmdlet returns TRUE.

Test-Path does not work correctly with all Windows PowerShell providers. For example, you can use Test-Path to test the path to a registry key, but if you use it to test the path to a registry entry, it always returns FALSE, even if the registry entry is present.





예제 6

C:\PS>Test-Path $pshome\PowerShell.exe -NewerThan "July 13, 2009"

Description
-----------
This command uses the NewerThan dynamic parameter to determine whether the PowerShell.exe file on the computer is newer than July 13, 2009. 

The NewerThan parameter works only in file system drives.





See Also

Concepts

파일 시스템 공급자

Other Resources

Clear-Content
Get-Content
Get-ChildItem
Get-Content
Get-Item
Remove-Item
Set-Content
Test-Path