Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 批处理文件,folderpath中的通配符,不知道通配符可以是什么_Windows_Batch File_Cmd_Wildcard - Fatal编程技术网

Windows 批处理文件,folderpath中的通配符,不知道通配符可以是什么

Windows 批处理文件,folderpath中的通配符,不知道通配符可以是什么,windows,batch-file,cmd,wildcard,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 Pr

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

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"
10.10.10.10
10.10.10.11
这是另一个批处理文件,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

@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"
10.10.10.10
10.10.10.11
批处理文件通过命令行执行

C:\> C:\copy.bat
问题是,如何使这个批处理文件工作,以便它将*识别为通配符

谢谢

只能在路径的最后一个元素中包含通配符

要执行所需操作,必须枚举
12.*
文件夹并选择一个。在这种情况下,将选择与通配符匹配的最后一个文件夹(当执行
do
子句中的代码时,变量将被覆盖)

尝试以下操作:

@echo off

For /D %%D in ("C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*") Do (
    Set "Dir=%%~fD\Data\Config"
)

If exist "%Dir%\SyLink.xm_" Del /q %Dir%\SyLink.xm_"
Ren "%Dir%\SyLink.xml" sylink.xm_bak
Del /q "%Dir%\SyLink.xml"

echo.
echo Copying new SyLink.xml
echo.
copy C:\SyLink.xml "%Dir%"


echo.
echo Deleting temp files
Del /q "c:\SyLink.xml"
/D切换文件夹的查找


%%~fD获取文件夹的完整路径。

请提问。