我有一个批处理文件试图替换
中的文件C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config
但是*因计算机而异,所以我不能有一个输入列表
这个批处理文件在另一个批处理文件中执行,从命令行调用。
这里是*路径的批处理文件,C:\script.bat
@echo off
if exist "C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config\SyLink.xm_" del /Q "C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config\SyLink.xm_"
ren "C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config\SyLink.xml" sylink.xm_bak
del /Q "C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config\SyLink.xml"
echo.
echo Copying new SyLink.xml
echo.
copy C:\SyLink.xml "C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config"
echo.
echo Deleting temp files
del /Q "c:\SyLink.xml"
这是另一个批处理文件 C:\copy.bat 调用第一个批处理文件,即 C:\script.bat
xcopy C:\sylink.xml \\10.10.10.10\c$
xcopy C:\sylink.xml \\10.10.10.11\c$
D:\pstools\psexec.exe @C:\clients.txt -c C:\Script.bat
C:\clients.txt
10.10.10.10
10.10.10.11
批处理文件通过命令行执行
C:\> C:\copy.bat
问题是,我如何使这个批处理文件工作,以便将 * 识别为通配符?
谢谢
最佳答案
for /d %%a in (
"C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*"
) do set "theFolder=%%~fa\Data\Config"
echo %theFolder%
您只能在路径的最后一个元素中包含通配符。
要执行您需要的操作,您必须枚举 12.*
文件夹并选择一个。在这种情况下,最后一个匹配通配符的文件夹被选中(因为 do
子句中的代码被执行,变量被覆盖)
关于windows - 批处理文件,文件夹路径中的通配符,不知道通配符是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25794369/