Last active
December 6, 2022 08:40
-
-
Save StephaneTy-Pro/2c2961ee0efd6451ed89 to your computer and use it in GitHub Desktop.
CMD: Check if a substring is in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: cherche si la chaine compiled est présente dans le nom de fichier | |
ECHO "truc-compiled" | findstr /r /c:"compiled" > nul && SET ISFOUND=1 || SET ISFOUND=0 | |
:: Orgigin | |
:: http://stackoverflow.com/questions/8756804/check-a-string-for-a-substring-in-a-batch-file-windows | |
:: Author dbenham | |
:: This regular expression example will search $1 for "BEGIN" at start of string, | |
:: "MID" anywhere in middle, and "END" at end. The search is case sensitive by default. | |
set "search=^BEGIN.*MID.*END$" | |
setlocal enableDelayedExpansion | |
echo(!$1!|findstr /r /c:"!search!" >nul && ( | |
echo FOUND | |
rem any commands can go here | |
) || ( | |
echo NOT FOUND | |
rem any commands can go here | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment