去除变量中的字符

时间:2018-08-10 12:58:05

标签: batch-file

我正在尝试从%%~ni中删除空格和逗号。通过将其放入新变量!url!中,我设法做到了。它回声很好,但是没有人知道为什么我不能在这里使用它:set "line=!line:REPLACE=!url!!"吗?

@echo off
setlocal enableextensions enabledelayedexpansion
for /R %%i in (*.csv) do (
ren "%%~i" temp.tmp
(for /F "usebackq tokens=*" %%f in ("%%~dpitemp.tmp") do (
        set "line=%%f"
        echo %%~ni

        set url=%%~ni
        set url=!url: =-!
        set url=!url:,=!
        echo !url!
        set "line=!line:REPLACE=!url!!"


        echo(!line!
)) > "%%~i"
del "%%~dpitemp.tmp"
)

1 个答案:

答案 0 :(得分:2)

回答其他有此问题的人

@echo off
setlocal enableextensions enabledelayedexpansion
for /R %%i in (*.csv) do (
ren "%%~i" temp.tmp
(for /F "usebackq tokens=*" %%f in ("%%~dpitemp.tmp") do (
        set "line=%%f"
        set url=%%~ni
        set "url=!url: =-!"
        set "url=!url:,=!"
        set "url=!url:(=!"
        set "url=!url:)=!"
        for /F "delims=" %%e in ("!url!") do set "line=!line:REPLACE=%%e!"
        echo(!line!
)) > "%%~i"
del "%%~dpitemp.tmp"
)