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!
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!
댓글
댓글 쓰기