파일 시스템용 Remove-Item

업데이트 날짜: 2014년 10월

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

파일과 폴더를 삭제합니다.

구문

Remove-Item [-Stream <string>] [<CommonParameters>]

설명

파일 시스템 드라이브에서 Remove-Item cmdlet은 파일 및 폴더를 삭제합니다.

Stream 동적 매개 변수를 사용하면 지정된 대체 데이터 스트림이 삭제되지만 파일이 삭제되지는 않습니다.

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

매개 변수

-Stream <string>

파일에서 지정한 대체 데이터 스트림을 삭제하지만 파일을 삭제하지는 않습니다. 스트림 이름을 입력합니다. 와일드카드가 지원됩니다. 이 매개 변수를 폴더에는 사용할 수 없습니다.

Stream은 파일 시스템 공급자가 Remove-Item cmdlet에 추가하는 동적 매개 변수입니다. 이 매개 변수는 파일 시스템 드라이브에만 작동합니다.

Remove-Item cmdlet을 사용하여 대체 데이터 스트림을 삭제할 수 있습니다. 하지만 인터넷에서 다운로드한 파일을 차단하는 보안 검사를 제거하는 것은 권장되는 방법이 아닙니다. 다운로드된 파일이 안전한지 확인하려면 Unblock-File cmdlet을 사용합니다.

이 매개 변수는 Windows PowerShell 3.0에서 도입되었습니다.

필수 여부

false

위치

명명됨

기본값

파이프라인 입력 적용 여부

false

와일드카드 문자 허용 여부

false

<CommonParameters>

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

입력 및 출력

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

입력

출력

예제 1

C:\PS>Get-Item C:\Test\Copy-Script.ps1 -Stream Zone.Identifier


   FileName: \\C:\Test\Copy-Script.ps1

Stream                   Length
------                   ------
Zone.Identifier              26


C:\PS>Remove-Item C:\Test\Copy-Script.ps1 -Stream Zone.Identifier

C:\PS>Get-Item C:\Test\Copy-Script.ps1 -Stream Zone.Identifier

get-item : Could not open alternate data stream 'Zone.Identifier' of file 'C:\Test\Copy-Script.ps1'.
At line:1 char:1
+ get-item 'C:\Test\Copy-Script.ps1' -Stream Zone.Identifier
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Test\Copy-Script.ps1:String) [Get-Item], FileNotFoundE
   xception
    + FullyQualifiedErrorId : AlternateDataStreamNotFound,Microsoft.PowerShell.Commands.GetItemCommand


C:\PS>Get-Item C:\Test\Copy-Script.ps1


    Directory: C:\Test


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---          8/4/2011  11:15 AM       9436 Copy-Script.ps1

Description
-----------
This example shows how to use the Stream dynamic parameter of the Remove-Item cmdlet to delete an alternate data stream. The stream parameter is introduced in Windows PowerShell 3.0.

The first command uses the Stream dynamic parameter of the Get-Item cmdlet to get the Zone.Identifier stream of the Copy-Script.ps1 file. 

The second command uses the Stream dynamic parameter of the Remove-Item cmdlet to remove the Zone.Identifier stream of the file.

The third command uses the Stream dynamic parameter of the Get-Item cmdlet to verify that the Zone.Identifier stream is deleted.

The fourth command Get-Item cmdlet without the Stream parameter to verify that the file is not deleted.





예제 2

C:\PS>Remove-Item C:\Test\*.*

Description
-----------
This command deletes all of the files with names that include a dot (.) from the C:\Test directory. Because the command specifies a dot, the command does not delete directories or files with no file name extension.





예제 3

C:\PS>Remove-Item * -Include *.doc -Exclude *1*

Description
-----------
This command deletes from the current directory all files with a .doc file name extension and a name that does not include "1". It uses the wildcard character (*) to specify the contents of the current directory. It uses the Include and Exclude parameters to specify the files to delete.





예제 4

C:\PS>Remove-Item -Path C:\Test\hidden-RO-file.txt -Force

Description
-----------
This command deletes a file that is both hidden and read-only. It uses the Path parameter to specify the file. It uses the Force parameter to give permission to delete it. Without Force, you cannot delete read-only or hidden files.





예제 5

C:\PS>Get-ChildItem * -Include *.csv -Recurse | Remove-Item

Description
-----------
This command deletes all of the CSV files in the current directory and all subdirectories recursively.

Because the Recurse parameter in this cmdlet is faulty, the command uses the Get-Childitem cmdlet to get the desired files, and it uses the pipeline operator to pass them to the Remove-Item cmdlet.

In the Get-ChildItem command, the Path parameter has a value of *, which represents the contents of the current directory. It uses the Include parameter to specify the CSV file type, and it uses the Recurse parameter to make the retrieval recursive.

If you try to specify the file type in the path, such as "-path *.csv", the cmdlet interprets the subject of the search to be a file that has no child items, and Recurse fails.





See Also

Concepts

파일 시스템 공급자

Other Resources

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