Here is my solution after many tests with if exist, pushd, dir /AD, etc...
@echo off
cd /d C:\
for /f "delims=" %%I in ('dir /a /ogn /b') do (
call :isdir "%%I"
if errorlevel 1 (echo F: %%~fI) else echo D: %%~fI
)
cmd/k
:isdir
echo.%~a1 | findstr /b "d" >nul
exit /b %errorlevel%
:: Errorlevel
:: 0 = folder
:: 1 = file or item not found
- It works with files that have no extension
- It works with folders named folder.ext
- It works with UNC path
- It works with double-quoted full path or with just the dirname or filename only.
- It works even if you don't have read permissions
- It works with Directory Links (Junctions).
- It works with files whose path contains a Directory Link.