在同一个文件夹下,可以存在名称相同的文件和文件夹么?
自己试验,倒是可以实现,只是有输出错误,不知道是什么原因……
@echo off
setlocal enabledelayedexpansion
for /f "skip=7 tokens=3,4" %%a in ('dir b') do (
set typeb=%%a
set nameb=%%b
if exist "a\!nameb!" (
for /f "skip=5 tokens=3" %%i in ('dir "a\!nameb!"') do (
set typea=%%i
if /I "!typea!"=="<dir>" (
echo Deleting dir "a\!nameb!"
rd /q /s "a\!nameb!" >nul
) else (
echo Deleting file "a\!nameb!"
del /q /s "a\!nameb!" >nul
)
)
)
)
pause