I have a batch file that attempts to replaces a file in
C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*\Data\Config
But the * varies from computer to computer, so it's not as if I can have an input list
This batch file is executed in another batch file, which is called from command-line.
Here is the batch file with the * path, 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"
And this is another batch file, C:\copy.bat that calls the first one, i.e. 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
Batch file is executed through the command-line
C:\> C:\copy.bat
Question is, how do I make this batch file work so it recognizes * as a wildcard?
Thanks
The asterisk (*) and question mark (?) are used as wildcard characters, as they are in MS-DOS and Windows. The asterisk matches any sequence of characters, whereas the question mark matches any single character.
Wildcards allow you to use a single specification to indicate a number of resources whose names match the wildcard pattern. System commands use three kinds of wildcards: Multiple-character trailing asterisk (*): The * indicates zero, one, or more characters, up to the maximum length of the string.
for /d %%a in (
"C:\Users\All Users\Symantec\Symantec Endpoint Protection\12.*"
) do set "theFolder=%%~fa\Data\Config"
echo %theFolder%
You can only include a wildcard in the last element of the path.
To do what you need, you have to enumerate the 12.*
folders and select one. In this case the last folder matching the wildcard is selected (as the code in the do
clause is executed, the variable is overwritten)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With