Batch file, wildcard in folderpath, no idea what the wildcard can be
Solution 1
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)
Solution 2
Try this:
@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 switch find for folders.
%%~fD gets full path from folder.
Glowie
Updated on September 12, 2020Comments
-
Glowie over 3 years
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