File searching and Remove the searched files in Powershell

This is very useful when you are managing your files in your computer (Windows)


1. Identify files in certain folder

>>> Get-ChildItem C:/testfolder/*


2. Identify files in certain folder and remove all of them

>>> Get-ChildItem C:/testfolder/* | ForEach ($_) {Remove-Item $_.fullname}


3. Search certain files including '.test'

>>> Get-ChildItem C:/* -Include *.test


4. Search certain files including '.test', but excluding the files which begin with 'abc'

>>> Get-ChildItem C:/* -Include *.test -Exclude abc*.test


5. Search the files including Sub folders

>>> Get-ChildItem C:/* -Include *.test -Recurse


6. Search the files including Sub folders and remove all of them

>>> Get-ChildItem C:/* -Include *.test -Recurse | ForEach ($_) {Remove-Item $_.fullname}


7. Search the files, Print them, and then remove all of them

>>> Get-ChildItem C:/* -Include *.test -Recurse || ForEach ($_) {Remove-Item $_.fullname}


Thanks,

Have Fun!

댓글

이 블로그의 인기 게시물

미국 포닥, 한국으로 돌아가는 이유? (Why do postdoc go back to Korea?)

미국 포닥 - 비지팅 포닥 VS 풀펀딩 포닥 (Visiting Scholar VS Postdoctoral Fellow)

미국 포닥 직위, 타이틀, 명칭? - Visiting Scholar, Postdoctoral Fellow, Research Associate, Research Scientist, Research Professor