Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch file, wildcard in folderpath, no idea what the wildcard can be

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

like image 970
Glowie Avatar asked Sep 11 '14 18:09

Glowie


People also ask

How do you use wildcards in DOS?

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.

What is a wildcard in command prompt?

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.


1 Answers

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)

like image 86
MC ND Avatar answered Oct 14 '22 00:10

MC ND