1
1

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 5 years have passed since last update.

コマンドプロンプトでフォルダのファイル数が1件以上の時だけ処理実行する判定の実装

Last updated at Posted at 2019-10-29

課題

  • バッチ処理で、targetフォルダにあるフォルダをすべてbackupフォルダに移したい。
  • ファイルがなければ実行したくない(ログ出力の関係で)(今回はログ出力は省略)

解答

FOR /F %%i in ('dir /B /S target ^| find /c /v ""') do set DIR_COUNT=%%i
if not %DIR_COUNT%==0 move /Y target\* backup\

pause

参考サイト

感想

  • ファイルのカウントの仕方
  • forコマンドによる代入の仕方
  • その際にパイプを含むコマンドを使う場合の対処

これを理解していないとダメだった。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?