디렉토리 트리에서 2 개의 파일을 검색하여 삭제하려고합니다. 삭제 된 파일의 경로 를 유지 하고 싶습니다 .
지금까지 내가 가진 것입니다.
#set the path to search for the file
$path = ".\"
#File name
$file = "GeneratedCode.cs"
$file2 = "TypedEnums.cs"
#Look for the file and delete every instance of it in all directories.
Get-Childitem $path -include $file -recurse | foreach ($_) {remove-item $_.fullname}
#Look for the file and delete every instance of it in all directories.
Get-Childitem $path -include $file2 -recurse | foreach ($_) {remove-item $_.fullname}
편집 : 파일의 모든 인스턴스를 삭제하고 싶다고 언급하는 것을 잊었습니다.
Get-ChildItem
cmdlet 의 결과를 변수에 저장합니다 $filesToDelete
. 그런 다음 개체를 Remove-Item
cmdlet으로 간단히 파이프 할 수 있습니다 (필요하지 않음 foreach
).
$filesToDelete = Get-Childitem $path -include $file -recurse
$filesToDelete | Remove-Item
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다