0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

powershellで指定フォルダ以下に存在する特定の名前のフォルダだけを削除したい

Last updated at Posted at 2021-01-30
foreach($DIRNAME in ("消したいフォルダ名A", "消したいフォルダ名B", "消したいフォルダ名C...")){
    Get-ChildItem -Recurse -Directory "ルートフォルダ" |
    Where-Object {$_.name -eq $DIRNAME} | Remove-Item -Recurse
}
  1. forearchなんかしないでWhere-Objectのところで-in $DIRNAMES的なことやれたほうがいいんだろうけどどういう書き方するのか知らない
  2. forearchするにしても最外なんかでやらないでWhereのところでやったほうが絶対に処理早いけどどう書くのがスマートなのかパッと出てくるほどpowershellに慣れてないしどうせ2回目以降のGet-ChildItemはオンメモリで一瞬で処理されるだろうから妥協した
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?