Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the subroutine for testing a name for wildcards?

8 views
Skip to first unread message

Timo Salmi

unread,
Dec 25, 2003, 8:49:06 AM12/25/03
to
42} What is the subroutine for testing a name for wildcards?

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

Matthias Tacke

unread,
Dec 25, 2003, 10:57:05 AM12/25/03
to
Timo Salmi wrote:

>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

Ritchie

unread,
Dec 25, 2003, 2:35:16 PM12/25/03
to
"Timo Salmi" <t...@UWasa.Fi> wrote in message news:bsepsi$1...@poiju.uwasa.fi...

> 42} What is the subroutine for testing a name for wildcards?

Hello Timo,

IMHO the overhead of a subroutine isn't justified:-

echo:%1 | findstr "* ?" >nul && echo/Wildcards found.

--
Ritchie, undo for mail


Timo Salmi

unread,
Dec 25, 2003, 3:21:29 PM12/25/03
to
Matthias Tacke <Matt...@Tacke.de> wrote:
> Timo Salmi wrote:
> >42} What is the subroutine for testing a name for wildcards?

> 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.

Timo Salmi

unread,
Dec 25, 2003, 3:27:05 PM12/25/03
to
Ritchie <qiournvdlirh...@hotmail.com> wrote:
> "Timo Salmi" <t...@UWasa.Fi> wrote in message news:bsepsi$1...@poiju.uwasa.fi...
> > 42} What is the subroutine for testing a name for wildcards?

> 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.

Ritchie

unread,
Dec 26, 2003, 5:43:55 AM12/26/03
to
"Timo Salmi" <t...@UWasa.Fi> wrote in message news:bsfh6p$4...@poiju.uwasa.fi...

> > 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

Timo Salmi

unread,
Dec 26, 2003, 2:36:56 PM12/26/03
to
Ritchie <qiournvdlirh...@hotmail.com> wrote:
> "Timo Salmi" <t...@UWasa.Fi> wrote in message news:bsfh6p$4...@poiju.uwasa.fi...
> > 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

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.

Ritchie

unread,
Dec 26, 2003, 7:15:59 PM12/26/03
to
"Timo Salmi" <t...@UWasa.Fi> wrote in message news:bsi2ko$g...@poiju.uwasa.fi...

> 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


0 new messages