我使用下面的代码删除Remove.txt中带有名字的文件夹
@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
set "filelist=Remove.txt"
for /f "delims=;" %%b in (%filelist: =3%) do if exist "c:\%%b" RD /S/Q "c:\%%b"
当文件夹存在且同时执行echo
时,是否有任何方法可以RD
显示某些文字?
答案 0 :(得分:1)
使用&
加入命令并在同一行上执行它们。
@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
set "filelist=Remove.txt"
for /f "delims=;" %%b in (%filelist: =3%) do if exist "c:\%%b" ECHO %%b & RD /S/Q "c:\%%b"
或者我们可以使用()用于多行代码
@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
set "filelist=Remove.txt"
for /f "delims=;" %%b in (%filelist: =3%) do if exist "c:\%%b" (
ECHO "%%b avaialble to delete"
RD /S/Q "c:\%%b"
)
答案 1 :(得分:0)
没有测试,但这样的事情应该有效:
@echo off
setlocal enableextensions
setlocal enabledelayedexpansion
set "filelist=Remove.txt"
for /f "delims=;" %%b in (%filelist: =3%) do if exist "c:\%%b" (
echo "%%b exists"
RD /S/Q "c:\%%b"
)