Batch file 替换文本文件批处理中的特殊字符

Batch file 替换文本文件批处理中的特殊字符,batch-file,replace,text-files,special-characters,Batch File,Replace,Text Files,Special Characters,哎哟。这个很疼。很难总结我的问题,因为我认为它有很多部分。相关和说明性代码部分: call %wabat% set _tmpGameP_gF=%waoutput% echo Result: %_tmpGameP_gF% if not exist "%_tmpGameP_gF%" ( echo That is an invalid file path or filename! Folder or file does not exist. Please re-select or re

哎哟。这个很疼。很难总结我的问题,因为我认为它有很多部分。相关和说明性代码部分:

call %wabat%
set _tmpGameP_gF=%waoutput%
echo Result: %_tmpGameP_gF%
if not exist "%_tmpGameP_gF%" (
        echo That is an invalid file path or filename! Folder or file does not exist. Please re-select or re-enter.  
        exit /b
        )
FOR %%i IN ("%_tmpGameP_gF%") DO (
        set _tmpbarefile=%%~ni
        set _tmpfilepath=%%~dpi
        set _tmpfilename=%%~nxi
    )
wabat.bat只是一个由Wizapp.exe生成的文本文件,包含以下内容:

set waoutput=I:\Tests\Somefile(North)[!].zip
set waoutnum=
脚本思想:第1部分测试文件是否存在,第2部分将文件拆分为多个组成部分

当然,问题在于这些特殊的角色。这种方法很好用,直到你在混合物中加入特殊的炭为止

同时,命令行显示:

set waoutput=I:\Tests\Somefile(North)[!].zip
(这是电话)

回显结果时(即使尝试回显%waoutput%),我得到:

很明显,这与!的解析有关

尝试了很多东西,但都没能成功——我觉得这是一座难以跨越的桥

哦,为了让它变得非常有趣,我不能重命名文件或文件夹。可以修改wabat.bat文件。考虑过搜索和替换wabat.bat中的所有特殊字符以添加转义字符,但在尝试这样做时完全迷失了方向+不确定这在变量的最终使用中有多有用等

我真的很感激在这一点上的任何帮助,因为7000行和击中砖墙!
感谢您的回复…

我认为您的问题在于您启用了延迟扩展

请尝试以下方法:

@echo off
set waoutput=I:\Tests\Somefile(North)[!].zip
echo %waoutput%

setlocal enabledelayedexpansion
echo %waoutput%
-->输出:

I:\Tests\Somefile(North)[!].zip
I:\Tests\Somefile(North)[].zip

如果文件中包含
,则在处理文件时必须禁用enabledexpansion字符

禁用延迟扩展应该足够了

Setlocal DisableDelayedExpansion
在调用wabat之前使用它,并且在调用时不使用百分号

Setlocal DisableDelayedExpansion