如下代码可以输出当前目录下所有文件的相对路径,但如果当前目录下存在含特殊字符名称的文件,如 ~!@#$%^&()-+.txt, 则会返回 “) was unexpected at this time” 的错误,程序退出。
请问,如何修改下面的代码,支持将含特殊字符名称的文件的相对路径列出来。
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('"dir /a-d /s /b /on *.* 2>NUL"') do (
set file=%%~fi
set file=!file:%cd%\=!
set file=!file:/=\!
echo. file---"!file!"
)
pause>nul
请问,如何修改下面的代码,支持将含特殊字符名称的文件的相对路径列出来。
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%i in ('"dir /a-d /s /b /on *.* 2>NUL"') do (
set file=%%~fi
set file=!file:%cd%\=!
set file=!file:/=\!
echo. file---"!file!"
)
pause>nul
