sourcetip

파워셸: Get-Item vs Get-ChildItem

fileupload 2023. 11. 4. 13:16
반응형

파워셸: Get-Item vs Get-ChildItem

나는 다음의 차이점을 이해하고 싶습니다.Get-Item그리고.Get-ChildItem. 한 가지 예로 가능한 경우.

Get-Item
지정한 위치에서 항목을 가져옵니다.

Get-Item .\foo
# returns the item foo

Get-Child 항목
하나 이상의 지정된 위치에 있는 항목 및 하위 항목을 가져옵니다.

Get-ChildItem .\foo
# returns all of the children within foo

참고: Get-ChildItem은 자식 디렉토리로 반복될 수도 있습니다.

Get-ChildItem .\foo -Recurse
# returns all of the children within foo AND the children of the children

enter image description here

enter image description here

enter image description here

만약 당신이 이런 폴더를 가지고 있다면.

Folder
├─ File-A
└─ File-B
  • 아이템이 폴더일 경우,Get-ChildItem항목의 자식을 반환합니다.
Get-Item Folder
# Folder

Get-ChildItem Folder
# File-A File-B
  • 항목이 폴더가 아닌 경우,Get-ChildItem아이템을 반환합니다.
Get-Item Folder\File-A
# File-A

Get-ChildItem Folder\File-A
# File-A

현재 디렉터리 가져오기

Get-Item .

현재 디렉터리에 있는 모든 항목 가져오기

# use Get-Item
Get-Item *
# or use Get-ChildItem
Get-ChildItem

모든 txt 파일 가져오기

# use Get-Item
Get-Item *.txt
# or use Get-ChildItem
Get-ChildItem *.txt

참조:

https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-Item?view=powershell-5.1

https://learn.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Management/Get-ChildItem?view=powershell-5.1

언급URL : https://stackoverflow.com/questions/38663391/powershell-get-item-vs-get-childitem

반응형