ファイル名に空白を含む複数ファイルをスクリプトから一括で削除する方法

Windowsクライアントで4万件くらいのファイルを一括で削除する必要があったので、調べてみました。

単純にfor分で回すと、パス/名前に空白が含まれているファイルは失敗するんですよね…。

以下の例で、対象ファイルはX:ドライブに存在するものとします。

ファイル名一覧はカレントフォルダに list.txt として作ってあるものとします。

@echo off
setlocal enabledelayedexpansion
set num=0
for /f "delims= usebackq" %%a in (list.txt) do (
  set /a num=num+1
  echo !num! "x:\%%a"
  del  "x:\%%a"
)

以上です。

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny