windows - 批处理文件,文件夹路径中的通配符,不知道通配符是什么

标签 windows batch-file cmd wildcard

我有一个批处理文件试图替换

中的文件
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/

相关文章:

windows - 鱿鱼透明+ HTTPS

.net - Windows CE 5.0 HTTPD <-> .NET 应用程序

java - 为什么Java程序使用.bat文件作为程序启动器?

mysql - 批处理执行的日志输出问题

file - 在 Windows 中使用批处理文件复制相同的文件

windows - 在 Windows 中打开文件的最基本方法

c++ - wsprintf() 的安全版本?

batch-file - 每隔一小时自动重启一个程序,有冷却时间

batch-file - 批处理文件是否支持导出陷阱?

windows - Github Desktop 没有在 cmd [windows] 上设置 'git'