CMD:文件夹存在时的回显文本

时间:2014-08-20 10:04:25

标签: if-statement cmd

我使用下面的代码删除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显示某些文字?

2 个答案:

答案 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"
)