The example below comes with multiple safeguards. It prepares a new
script, which you then can run. The resulting script comes with
rem:s and the deletion with the /p (prompt for confirmation) switch.
The possibility of file/folder names with spaces has been taken into
account.
@echo off & setlocal enableextensions
::
:: Which folder to examine (customize the path!)
set targetdir_=c:\_m\test two
if not exist "%targetdir_%\*.*" (
echo Folder "%targetdir_%" not found
goto :EOF)
::
:: Let the script prepare a new one (customize the path!)
set script_="c:\_m\doit.cmd"
if exist %script_% del %script_%
::
:: Identify the files to be deleted
for /f "
skip=20 delims=" %%f in (
'dir /a:-d /b /o:-d "%targetdir_%\*.*"') do (
echo rem del /p "%targetdir_%\%%~nf%%~xf">>%script_%)
::
:: Tell me about it
for /f "delims=" %%s in (%script_%) do if exist %%~fs (
echo The script "%%~fs" is ready
echo %%~ts %%~as %%~zs)
endlocal & goto :EOF
The contents of DOIT.CMD could become e.g.
rem del /p "c:\_m\test two\CMDFAQ2.CMD"
rem del /p "c:\_m\test two\test (4!).txt"
rem del /p "c:\_m\test two\test & 3.txt"
rem del /p "c:\_m\test two\MYTEST.CMD"
rem del /p "c:\_m\test two\VBSFAQ.VBS"
rem del /p "c:\_m\test two\VBSFAQ2.VBS"
rem del /p "c:\_m\test two\BATFAQ.BAT"