DRAFT
@echo off & setlocal enableextensions
::
:: Demo
set filename_="My * file"
call :IsWildSub %filename_% isWild
if "%isWild%"=="yes" (
echo %filename_% contains wildcards
) else (
echo No wildcards in %filename_%)
::
set filename_="My file"
call :IsWildSub %filename_% isWild
if "%isWild%"=="yes" (
echo %filename_% contains wildcards
) else (
echo No wildcards in %filename_%)
endlocal & goto :EOF
:: ===============================================================
:: Does a name contain wildcards * and/or ?
:IsWildSub
setlocal enableextensions
echo %1|find "*">nul
if %errorlevel% EQU 0 (endlocal & set %2=yes& goto :EOF)
echo %1|find "?">nul
if %errorlevel% EQU 0 (endlocal & set %2=yes& goto :EOF)
endlocal & set %2=no& goto :EOF
The output
D:\TEST>cmdfaq
"My * file" contains wildcards
No wildcards in "My file"
All the best, Timo
--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful script files and tricks ftp://garbo.uwasa.fi/pc/link/tscmd.zip
>42} What is the subroutine for testing a name for wildcards?
>
>
What about commands which resolve folder names to contained files?
But maybe this indirect wildcard is a different question for
(un-)ambiguity.
--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
Hello Timo,
IMHO the overhead of a subroutine isn't justified:-
echo:%1 | findstr "* ?" >nul && echo/Wildcards found.
--
Ritchie, undo for mail
> What about commands which resolve folder names to contained files?
Thank you! It actually is about any string containing either * or ?.
Still, perhaps I had better rephrease this as
"What is the subroutine for testing a filename for wildcards?"
even if that is not quite accurate, either.
> IMHO the overhead of a subroutine isn't justified:-
> echo:%1 | findstr "* ?" >nul && echo/Wildcards found.
It is a good point. If one is striving for efficiency as the primary
goal, you are quite right. However, for a hopefully pedagogical FAQ,
I am not. I am trying to cover the different techniques of CMD
command line script programming. One of the important properties
introduced with it is the usage of subroutines.
> > IMHO the overhead of a subroutine isn't justified:-
> > echo:%1 | findstr "* ?" >nul && echo/Wildcards found.
>
> It is a good point. If one is striving for efficiency as the primary
> goal, you are quite right. However, for a hopefully pedagogical FAQ,
> I am not. I am trying to cover the different techniques of CMD
> command line script programming. One of the important properties
> introduced with it is the usage of subroutines.
Change it to this then:
:IsWildSub
echo:%* | findstr "* ?" >nul & goto :EOF
> Change it to this then:
> :IsWildSub
> echo:%* | findstr "* ?" >nul & goto :EOF
Thank you. But that's not quite it. It should return the status.
Else it is just the same thing in a slightly different part of the
script.
The status is 'returned' by way of setting the errorlevel.
set "var=My * file.txt"
call :IsWildSub %var% && (echo/Contains wildcards)
goto :EOF
:IsWildSub
echo:%* | findstr "* ?" >nul & goto :EOF
--
Ritchie