无法在批处理脚本中使用echo命令显示变量值

时间:2017-09-17 00:24:10

标签: batch-file

我正在尝试整理一个批处理脚本,但我仍然试图分配一个变量然后用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

那么,我做错了什么?_?

0 个答案:

没有答案