我尝试从文件列表中提取文件名,替换特定字符串并将其提供给进程。然而,我被困在更换。有什么想法吗?
@echo on
setlocal ENABLEDELAYEDEXPANSION
for %%f in (*.txt) do (
REM echo %%~nf
set filename=%%~nf
echo %@filename%
set Replaced=replaced
set @ver=!%filename:ToBeReplace=%Replaced%!
echo %@ver%
)
来自echo
的{{1}}不是我的预期。提前谢谢!
答案 0 :(得分:1)
我在与以下脚本相同的文件夹中有一个名为something.txt
的文件:
@echo off
setlocal ENABLEDELAYEDEXPANSION
set "old=some"
set "new=else"
for %%f in (*.txt) do (
REM echo %%~nf
set "filename=%%~nf"
echo !filename!
rem set Replaced=replaced
set "@ver=!filename:%old%=%new%!"
echo !@ver!
)
执行后的optuput是:
东西
elsething