【发布时间】:2013-10-19 19:25:24
【问题描述】:
我希望能够执行 %~p 以仅查看文件的路径。但是在循环中使用它时我无法获得正确的语法(使用 EnableDelayedExpansion)
这是我的代码:
@echo off
set "dir1=%TMP%\opt"
set "dir2=c:\opt"
set "empty="
setlocal EnableDelayedExpansion
for /f %%F in ('dir /a:-d /s /b /r "%dir1%"') do (
set "file_path=%%F"
set "file_name=%%~nF"
set "new_path=!file_path:%dir1%=%dir2%!"
set "new_path=!new_path:!file_name!=%empty%" //This command is problematic
echo !new_path!
)
endlocal
我有什么办法吗?
【问题讨论】:
标签: windows variables batch-file for-loop