我正在尝试整理一个批处理脚本,但我仍然试图分配一个变量然后用echo命令显示它的值:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
chcp 65001
for /f "eol=| delims=" %%f in ('dir /b') do (
set "file=%%f"
echo %%f | tr -cd "[]()A-Za-z0-9_.\-" > temp.txt
set /p filename=<temp.txt
setlocal EnableDelayedExpansion
echo %%f rem output: system can't write in specified device
echo %file% rem output: system can't write in specified device
echo !file! rem output: system can't write in specified device
echo !filename! rem this works: it shows correctly the content of variable filename
endlocal
)
endlocal
exit /b
那么,我做错了什么?_?