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

The all-command "/s" switch emulator - SWEEP.BAT

8 views
Skip to first unread message

Secret_Doom

unread,
Feb 9, 2002, 6:32:04 PM2/9/02
to
Hi folks!
Have you ever wanted to apply a command to all subdirectories under
the current directory, but that command hadn't such a possibility? A
common example would be: attempt to rename all files with extention
.123 to .abc in all subdirs from CD. How can you do such a thing?

Well, I've developed a batch script that would do that for you: it
will enter every subdirectory from the current directory and apply the
command given. It's below:

http://www.batch.hpg.com.br/sweep.txt

Actualy, I've heard sometime ago about SWEEP.EXE, a microsoft
application that would do the same. But that application was from an
old DOS, and wouldn't support long folder names. My script DOES
support long file names.

The bad side from it is that it uses 2 assembler codes and one "debug
program".

I've tested it under Windows 98 and also under Dos6.22, works on both.
It doesn't require any application that isn't present at WinNT,
however I have no idea if it works on NT.

So... What do you think of it? Have anyone did this before?

-- Secret_Doom - Leonardo Pignataro --

secre...@hotmail.com
www.batch.hpg.com.br

Timo Salmi

unread,
Feb 10, 2002, 2:03:08 AM2/10/02
to
Secret_Doom <secre...@hotmail.com> wrote:
> Have you ever wanted to apply a command to all subdirectories under
> the current directory, but that command hadn't such a possibility? A

> So... What do you think of it? Have anyone did this before?

Basically, the trick is

dir c:\xxx\yyy\*.* /s /l /b|gawk '{printf"WhateverCommand %%s\n",$0}'

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
Timo's FAQ materials at http://www.uwasa.fi/~ts/http/tsfaq.html

Timo Salmi

unread,
Feb 10, 2002, 2:06:54 AM2/10/02
to
Secret_Doom <secre...@hotmail.com> wrote:
> Have you ever wanted to apply a command to all subdirectories under
> the current directory, but that command hadn't such a possibility? A

> So... What do you think of it? Have anyone did this before?

Basically, the trick is


dir c:\xxx\yyy\*.* /s /l /b|gawk '{printf"WhateverCommand %%s\n",$0}'

Furthermore, there is a SWEEP.BAT in

213335 Feb 6 2002 ftp://garbo.uwasa.fi/pc/ts/tsbat72.zip
tsbat72.zip A collection of useful batch files and tricks, T.Salmi

Timo Salmi

unread,
Feb 10, 2002, 4:09:00 AM2/10/02
to
In article <a4566e$n...@poiju.uwasa.fi>, Timo Salmi <t...@UWasa.Fi> wrote:

> Secret_Doom <secre...@hotmail.com> wrote:
> > So... What do you think of it? Have anyone did this before?

> Basically, the trick is
> dir c:\xxx\yyy\*.* /s /l /b|gawk '{printf"WhateverCommand %%s\n",$0}'

The dir in my solution needs the /a:-d switch to not include the
actual directory names along the route. We only wish to tranverse
the files.

William Allen

unread,
Feb 10, 2002, 5:04:37 AM2/10/02
to
"Secret_Doom" wrote in message
...snip

> Have you ever wanted to apply a command to all subdirectories under
> the current directory, but that command hadn't such a possibility?

Asked and answered so many, many times - yawn!

The XCOPY cyclic error suppression technique allows Windows
95/98/ME users to execute commands in all subfoders, whether
they have hidden or system attributes or not. It doesn't need any
of the clutter of assorted third-party utilities. It doesn't even use
Debug, though of course, Debug is a common feature of DOS
since 1.0 so is fully valid in all Batch files. This technique handles
traversing of long folder names, whether or not they contain [Space]s.

Here is an account of the method.

=====Batch technique for Windows 95/98/ME GUI

In Windows 95/98/ME, the usual XCOPY cyclic copy error can
be avoided. Combining this feature with the /L switch (see Note 1)
provides powerful batch techniques. One application is a very
compact script to execute a FOR IN DO loop in all subfolders.

===Details

The command line:
xcopy C:\NUL C:\ /l/n/s

produces a full list of all foldernames (short-name alias format)
on drive C: as full specifications, excluding the initial C:\ but
with \NUL appended to each folder specification (see Note 2)
(to include empty folders, use /e instead of /s)

This means the list can be written to a temporary Batch file and
"bounced" off the PROMPT (see Note 3) without the need to clear
the path, and without the need to work in an empty folder, and
without interference from foldernames happening to coincide with
internal commands. As a result, except for foldernames that happen
to contain the % symbol, the PROMPT prefix method is reliable,
quick, and simple for processing this foldername list.

By using the fact that:

CD C:\FOLDER\PATH\NUL\..

will make C:\FOLDER\PATH the current folder, it becomes
simple to implement a FOR IN DO loop in all subfolders,
producing the effect of a /Subfolder switch with FOR IN DO
in a very compact Batch script (since all the usual precautions
for PROMPT bounce prefixing are unnecessary).

Alternatively, the folder scan may be rooted on C:\AnyFolder
and a FOR IN DO loop executed on C:\AnyFolder and
all its subfolders.

All this can apply to any other drive apart from C: as you wish.

In the two demos that follow, the FOR IN DO command used is:
FOR %%F IN (*.TMP) DO ECHO.%%F

This demo shows the full FOR IN DO scan of all folders of C:

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

ECHO.@PROMPT CALL %0 GOTO: _FSCAN C:\>%TEMP%.\FL.BAT
xcopy C:\NUL C:\ /l/n/s|find /v " ">>%TEMP%.\FL.BAT
ECHO.@ECHO OFF>>%TEMP%.\FL.BAT
%COMSPEC% NUL/c %0 GOTO: _PREFIX %TEMP%.\FL.BAT
ECHO.EXIT|%COMSPEC%/e:4096/k PROMPT $N:$_CD $P$_:>%TEMP%.\H.BAT
FOR %%F IN (CALL DEL) DO %%F %TEMP%.\PF.BAT
DEL %TEMP%.\H.BAT

GOTO EOF (=Subroutine code follows=)
:_FSCAN
C:
CD %3\..
:: This FOR IN DO loop executed in every folder on C:
FOR %%F IN (*.TMP) DO ECHO.%%F
CALL %TEMP%.\H.BAT

GOTO EOF (=Subroutine code follows=)
:_PREFIX
%COMSPEC%/c %3>%TEMP%.\PF.BAT
DEL %3

:EOF (End-of-file)

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The
Batch code above was written and tested in the Win9x GUI.

This version shows the syntax for a FOR IN DO rooted on C:\AnyFolder
that continues recursively into all subfolders of C:\AnyFolder

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

SET BASE=C:\AnyFolder

ECHO.@PROMPT CALL %0 GOTO: _FSCAN >%TEMP%.\FL.BAT
xcopy %BASE%\NUL C:\ /l/n/s|find /v " ">>%TEMP%.\FL.BAT
ECHO.@ECHO OFF>>%TEMP%.\FL.BAT
%COMSPEC% NUL/c %0 GOTO: _PREFIX %TEMP%.\FL.BAT
ECHO.EXIT|%COMSPEC%/e:4096/k PROMPT $N:$_CD $P$_:>%TEMP%.\H.BAT
FOR %%F IN (CALL DEL) DO %%F %TEMP%.\PF.BAT
DEL %TEMP%.\H.BAT

SET BASE=

GOTO EOF (=Subroutine code follows=)
:_FSCAN
%BASE%\
CD %BASE%\%3\..
:: This FOR IN DO loop executed in BASE and all subfolders of BASE
FOR %%F IN (*.TMP) DO ECHO.%%F
CALL %TEMP%.\H.BAT

GOTO EOF (=Subroutine code follows=)
:_PREFIX
%COMSPEC%/c %3>%TEMP%.\PF.BAT
DEL %3

:EOF (End-of-file)

====End cut-and-paste (omit this line)
To use the code above, cut-and-paste the text between the ==== lines
into a file with extension .BAT and base name of your choice. Lines
that don't begin with two spaces have wrapped in transmission. The
Batch code above was written and tested in the Win9x GUI.

--
William Allen

Note 1:
Original thread where the cyclic copy suppression technique
is developed
From: "William Allen"
Newsgroups: alt.msdos.batch
Subject: XCOPY whole-disk listings without a cyclic copy error
Date: Sat, 3 Nov 2001 12:59:15 -0000
Message-ID: <9s0ppg$10bnc7$1...@ID-55970.news.dfncis.de>

Note 2:
Original post for foldername listing using C:\NUL technique
From: "William Allen"
Newsgroups: alt.msdos.batch
Subject: Re: XCOPY whole-disk listings without a cyclic copy error
Date: Sat, 10 Nov 2001 23:24:08 -0000
Message-ID: <9skdcv$13qtnd$1...@ID-55970.news.dfncis.de>

Note 3:
Some general approaches to processing a list from a file,
detailed syntax, the pitfalls of different methods, and
some indications of how to work around them:
From: "William Allen"
Newsgroups: alt.msdos.batch
Subject: List processing or Bouncing off the PROMPT (LONG)
Date: Sat, 17 Nov 2001
Message-ID: <9t5baj$e2ss$2...@ID-55970.news.dfncis.de>

You can read old Usenet posts at:
http://groups.google.com/advanced_group_search

Note: Google search by Message-ID is usually the quickest.
The Message-ID is the identifier in the <angle> brackets.
Simply cut-and-paste the Message-ID into Google page above.


Secret_Doom

unread,
Feb 10, 2002, 11:15:59 AM2/10/02
to
"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message news:<a45gl1$1c94t9$1...@ID-55970.news.dfncis.de>...

I CAN'T BELIEVE THIS! Every time I make a ultra-complex script and
post here either Willam Allen or Outsider say "oh, try this tiny
pure-batch error-free all-compatible script I've done..." hehe...

Brillian methods you've got there -- I must say:
- Getting folders' short names
- Prefixing

I took some time to understand the prefixing part, but I've got it
now.
Thanks for sharing knowledge.

Oh, I know I shouldn't be asking this here, but since we're already
talking about this script... Will it work on NT ?

William Allen

unread,
Feb 10, 2002, 1:20:18 PM2/10/02
to
"Secret_Doom" wrote in message
...snip
> I took some time to understand the prefixing part, but I've got it
> now.
> Thanks for sharing knowledge.

A pleasure to share with you :-)

>
> Oh, I know I shouldn't be asking this here, but since we're already
> talking about this script... Will it work on NT ?

It's perfectly OK to ask that - ignore the silly "rules" about NT,
they have no status except as personal opinions (which few seem
to share as far as I can judge). Simple Batch-related questions
about NT/2000/XP - particularly on cross-platform issues and
comparisons - are on-Topic as far as I am concerned.

None of the sweep methods are relevant to NT - at least not in its
Windows 2000 and later manifestations, since its FOR IN DO
internal command is vastly expanded. For example FOR /R
in Windows 2000 walks the entire folder path rooted at wherever
you want to start.

A good way to find out more - for absolutely free - about
Windows 2000 Batch enhancements is to download and
play with Win95cmd.exe - the free Microsoft batch enhancer
for Windows 95/98/ME - and questions about it are on-Topic
in alt.msdos.batch as far as I am concerned and that's _not_
going to change (again ignore the silly "rules" - there are
no rules, only personal opinions). With Win95cmd.exe in
your system path you can play with some advanced Windows
2000 syntax in Windows 95/98/ME without installing Windows
2000 at all.

For more details of Win95cmd.exe including where to get
it, how to use it, and many syntax examples, see my post:

Win95cmd Batch enhancer for Windows 95/98/ME users
http://groups.google.com/groups?selm=a04ecl$isbjh$1...@ID-55970.news.dfncis.de
Date: 23 Dec 2001

and:

Batch arithmetic with the Win95cmd Batch enhancer
http://groups.google.com/groups?selm=9vdkh4$efe02$1...@ID-55970.news.dfncis.de
Date: 14 Dec 2001

--
(pp) William Allen


Charles Dye

unread,
Feb 10, 2002, 7:21:19 PM2/10/02
to
On 9 Feb 2002 15:32:04 -0800, secre...@hotmail.com (Secret_Doom)
wrote:

>Actualy, I've heard sometime ago about SWEEP.EXE, a microsoft
>application that would do the same. But that application was from an
>old DOS, and wouldn't support long folder names. My script DOES
>support long file names.

Out of curiosity, and meaning no criticism: Why would it matter
that the SWEEP utility doesn't use long filenames? It seems to
me that whether it changes the current directory to G:\PROGRA~1
or to "g:\Program Files" the result is the same.

--
Charles Dye ras...@highfiber.com


Secret_Doom

unread,
Feb 11, 2002, 12:14:52 AM2/11/02
to
Hi again William, thanks for the reply.

You've already told me about that enhancer and I've already said I
would get it -- but I didn't until now. However, I WILL get it this
time.

So you say that script is senseless in NT because that's the sort of
thing you can do with one-line-command... Good to know that, I'm
trying to help a Win2K user with renaming all *.bla to *.pdf from all
subdirs. I've made crazy attempts to suit a Win9x batch in NT (without
having how to test it!) in order to make that... I feel stupid with
now hehe...

Good to hear that what you said about the "rules" from
alt.msdos.batch, sometimes some people are "a little bit" (VERY MUCH)
annoying when regarding that. You do know what I mean.

-- Secret_Doom - Leonardo Pignataro --

secre...@hotmail.com
www.batch.hpg.com.br


"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message news:<a46dm4$1br95d$1...@ID-55970.news.dfncis.de>...

William Allen

unread,
Feb 11, 2002, 4:23:33 AM2/11/02
to
"Charles Dye" wrote in message
> On 9 Feb 2002 15:32:04 -0800, (Secret_Doom)

> wrote:
>
> >Actualy, I've heard sometime ago about SWEEP.EXE, a microsoft
> >application that would do the same. But that application was from an
> >old DOS, and wouldn't support long folder names. My script DOES
> >support long file names.
>
> Out of curiosity, and meaning no criticism: Why would it matter
> that the SWEEP utility doesn't use long filenames? It seems to
> me that whether it changes the current directory to G:\PROGRA~1
> or to "g:\Program Files" the result is the same.

And, to add further information, the SWEEP.EXE utility is superseded
by the Microsoft utility FORFILES.EXE supplied in the Windows 98
Resource Kit (along with many other Batch utilities) and is also
downloadable free from:

FORFILES.EXE and other free Microsoft utilities are available from:
ftp://ftp.microsoft.com/Services/TechNet/samples/ps/win98/reskit/scrpting/
and click on the name of the required Batch Tool.

And for detailed documentation, usage instructions, and syntax examples
for Batch usage of all the above Batch tools:
ftp://ftp.microsoft.com/Services/TechNet/samples/ps/win98/reskit/help/win98rk.chm
This is a fully indexed and searchable compiled help file.

--
(pp) William Allen


pchelp

unread,
Feb 11, 2002, 5:24:43 AM2/11/02
to
Charles Dye wrote:

I have never seen a Microsoft utility named SWEEP.EXE, but I do have a
copy of SWEEP.COM by Charles Petzold (Ziff-Davis), dating from 1985. It
executes any command in the current directory and in every subdirectory
of the current dir. It's simple-minded and literal. It runs any
command including those containing or involving long filenames. Don't
bother trying the /? switch. It'll run that too.

If anyone is interested, I have placed SWEEP.COM and its companion
SWEEP.DOC (text) in a ZIP archive, and placed that on my site:

http://pc-help.org/pub/sweep.zip

pchelp

Timo Salmi

unread,
Feb 11, 2002, 11:33:26 AM2/11/02
to
In article <3C679B...@pc-help.org>, pchelp <pch...@pc-help.org> wrote:
> I have never seen a Microsoft utility named SWEEP.EXE, but I do have a
> copy of SWEEP.COM by Charles Petzold (Ziff-Davis), dating from 1985. It

> If anyone is interested, I have placed SWEEP.COM and its companion


> SWEEP.DOC (text) in a ZIP archive, and placed that on my site:
> http://pc-help.org/pub/sweep.zip

Not that it really is any of my business, but _if_ it is the same
sweep as distributed by the PC-Magazine, then altering their package
is contrary to their distribution policies. I happen to know this
since I have corresponded about the issue at length with them way
back then. The package which has their official go-ahead is

17653 Dec 13 1987 ftp://garbo.uwasa.fi/pc/pcmagvol/vol4n24.zip
vol4n24.zip Contains SWEEP and WAITASEC

Incidentally, there also is the more general

74167 Jul 21 1992 ftp://garbo.uwasa.fi/pc/filefind/target15.zip
target15.zip The McAfee File Locator and Manipulator (good)

Secret_Doom

unread,
Feb 11, 2002, 12:45:26 PM2/11/02
to
I've just _HEARD_ about SWEEP.EXE, I've never actually seen it.
And I also _HEARD_ that it would FAIL if there are any long name folders.

But I just _HEARD_ all that. (and it was a while ago)

BTW, win95cmd.exe is really impressive, Willam Allen!

William Allen

unread,
Feb 11, 2002, 1:32:31 PM2/11/02
to
"Secret_Doom" wrote in message
...snip
> BTW, win95cmd.exe is really impressive, Willam Allen!

Yes, I think so, too. Although certainly not all of the syntax will
work in Windows 95/98 because some of it needs OS support
from Windows 2000, it's surprising how much does.

For example, this simple extraction of hour, minute, second, and
hundreths of seconds to separate variables makes use of the
ability to run several commands in one FOR IN DO line, and
uses its string parsing function :~ that parses variables. It uses
the idea of executing a Subroutine in a Win95cmd child shell to
make use of it from a normal Batch script run in a normal DOS
box or by double-clicking.

All you need is Win95cmd.exe in the system path.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

win95cmd/c %0 GOTO: _TMTOKEN
FOR %%C IN (CALL DEL) DO %%C %TEMP%.\T.BAT

ECHO. Hour=%H% Minute=%M% Second=%S% 1/100Second=%T%
FOR %%V IN (H M S T) DO SET %%V=

GOTO EOF (=Subroutine code follows=)

:_TMTOKEN
FOR /F "tokens=1,2,3,4 delims=:.," %%J IN ("%TIME%") DO (
SET H=%%J & SET M=%%K & SET S=%%L & SET T=%%M )

:: Replace any leading [Space] with a leading [0]
IF "%H:~0,1%"==" " SET H=0%H:~1,1%
REM Initialise a workfile>%TEMP%.\T.BAT
FOR %%V IN ("H=%H%" "M=%M%" "S=%S%" "T=%T%") DO ECHO.SET %%~V>>%TEMP%.\T.BAT

:EOF (End-of-file)

====End cut-and-paste (omit this line)

Cut-and-paste text between the ==== lines into file with extension .BAT
(and suitable base name). Lines that don't begin with two spaces have
wrapped accidentally. The code sample is purely for demonstration and
study purposes. It was written/tested in the Win9x GUI with Win95cmd.exe
in the system path.

The huge advantage of Win95cmd.exe has is that the syntax you learn
will be re-usable knowledge should you decide to write Batch files in
a Win2000 environment. Much more useful than eccentric third-party
programs.

And the help information obtained by typing
for /?
set /?
call /?
and so on is very impressive.

Details and download for Win95cmd see post:


Win95cmd Batch enhancer for Windows 95/98/ME users
http://groups.google.com/groups?selm=a04ecl$isbjh$1...@ID-55970.news.dfncis.de
Date: 23 Dec 2001

--
(pp) William Allen
CaveMan1: Hey look at this, I've reinvented the wheel!
CaveMan2: That's no good. Without the corners, it'll just roll away.


Dr John Stockton

unread,
Feb 11, 2002, 2:42:43 PM2/11/02
to
JRS: In article <a52f43af.02020...@posting.google.com>, seen
in news:alt.msdos.batch, Secret_Doom <secre...@hotmail.com> wrote at
Sat, 9 Feb 2002 15:32:04 :-

>Have you ever wanted to apply a command to all subdirectories under
>the current directory, but that command hadn't such a possibility? A
>common example would be: attempt to rename all files with extention
>.123 to .abc in all subdirs from CD. How can you do such a thing?

HUNT *.123 s p q "ren" "*.abc" u

will do that, at the command line. Omit u for test. It can also be
date-, size- or attribute- selective, and, without u, lets one decide
which files to change. HUNT via sig line 3.

--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL: http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL: http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.

pchelp

unread,
Feb 11, 2002, 10:09:12 PM2/11/02
to
Timo Salmi wrote:

> In article <3C679B...@pc-help.org>, pchelp <pch...@pc-help.org> wrote:

> > If anyone is interested, I have placed SWEEP.COM and its companion
> > SWEEP.DOC (text) in a ZIP archive, and placed that on my site:
> > http://pc-help.org/pub/sweep.zip

> Not that it really is any of my business, but _if_ it is the same
> sweep as distributed by the PC-Magazine, then altering their package
> is contrary to their distribution policies. I happen to know this
> since I have corresponded about the issue at length with them way
> back then. The package which has their official go-ahead is

> 17653 Dec 13 1987 ftp://garbo.uwasa.fi/pc/pcmagvol/vol4n24.zip
> vol4n24.zip Contains SWEEP and WAITASEC

Thanks. I looked in vain for the original download in my archives. I'm
fairly sure that the form in which I received it back when was _not_
their package; probably it was passed on by a friend in about 1990.
(I'm a bit of a pack-rat; my archives are an almost perfect record of my
file acquisitions.)

I'll take the file off my site. It was only there to help with the
topic at hand. I welcome your reminder; I know you want to see
respectful treatment of others' works.


> Incidentally, there also is the more general

> 74167 Jul 21 1992 ftp://garbo.uwasa.fi/pc/filefind/target15.zip
> target15.zip The McAfee File Locator and Manipulator (good)

> All the best, Timo

Much appreciated.

pchelp

Charles Dye

unread,
Feb 11, 2002, 10:55:53 PM2/11/02
to
On Mon, 11 Feb 2002 02:24:43 -0800, pchelp <pch...@pc-help.org> wrote:

>I have never seen a Microsoft utility named SWEEP.EXE, but I do have a
>copy of SWEEP.COM by Charles Petzold (Ziff-Davis), dating from 1985. It
>executes any command in the current directory and in every subdirectory
>of the current dir. It's simple-minded and literal. It runs any
>command including those containing or involving long filenames. Don't
>bother trying the /? switch. It'll run that too.

If memory serves, that one doesn't recurse into subdirectories with
the Hidden or System attributes set. Would probably be easy to patch,
though. (I don't know whether Secret_Doom's script would handle such
directories correctly....?)

--
Charles Dye ras...@highfiber.com


Todd Vargo

unread,
Feb 12, 2002, 12:00:01 AM2/12/02
to

"pchelp" <pch...@pc-help.org> wrote

> I'll take the file off my site. It was only there to help with the
> topic at hand. I welcome your reminder; I know you want to see
> respectful treatment of others' works.

You could replace it with the official file or even link to it.

--
Todd Vargo (body of message must contain my name to reply by email)

Secret_Doom

unread,
Feb 12, 2002, 1:24:06 AM2/12/02
to
William Allen wrote: (snipped)

> And the help information obtained by typing
> for /?
> set /?
> call /?
> and so on is very impressive.

Yes, they're very impressive. Very LONG also hehe. I were very
surprised with the info on both SET and CALL commands (very simple
commands in Win98). I got so surprised that I made a "pause/?" to
check it there was any unexpected info there also hehe.

With such info I don't miss a HELP command (like the one from
Dos6.22).
The FOR command is very impressive also, and the preset variables
(%time%,%date%, any other more I didn't figure out yet) are very
useful.

Charles Dye wrote: (snipped)


> If memory serves, that one doesn't recurse into subdirectories with
> the Hidden or System attributes set. Would probably be easy to patch,
> though. (I don't know whether Secret_Doom's script would handle such
> directories correctly....?)

Humm, I forgot about the System folders. So the list creation should
be (check the script if you don't know what I'm talking about):

dir/s/b/ad-h-s >> %temp%.\$$tmp.dat
dir/s/b/adh-s >> %temp%.\$$tmp.dat
dir/s/b/ads-h >> %temp%.\$$tmp.dat

Anyway I've decided to abandon such script (it's already named
OLDSWEEP.BAT at my HD hehe)

William Allen

unread,
Feb 12, 2002, 2:24:11 AM2/12/02
to
"Secret_Doom" wrote in message

> William Allen wrote: (snipped)
> > And the help information obtained by typing
> > for /?
> > set /?
> > call /?
> > and so on is very impressive.
>
> Yes, they're very impressive. Very LONG also hehe. I were very
> surprised with the info on both SET and CALL commands (very simple
> commands in Win98). I got so surprised that I made a "pause/?" to
> check it there was any unexpected info there also hehe.

Also try, for example
if /?

and see that you can use comparisons such as:
EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal

> With such info I don't miss a HELP command (like the one from
> Dos6.22).
> The FOR command is very impressive also, and the preset variables
> (%time%,%date%, any other more I didn't figure out yet) are very
> useful.

Note the following extracts from SET /? help:

%CD% - expands to the current directory string.
%DATE% - expands to current date using same format as DATE command
%TIME% - expands to current time using same format as TIME command
%RANDOM% - expands to a random decimal number between 0 and 32767.
%ERRORLEVEL% - expands to the current ERRORLEVEL value

Note that ERRORLEVELs are lost when you transfer control
to a child shell, or return to a parent shell.

Note that RANDOM is intialised as the Win95cmd process starts, so
if you shell to it with, say:

win95cmd /c ECHO.%%RANDOM%%

you'll always see much the same number produced. To make
use of it, you need to use my idea of running a Subroutine
with a Win95cmd /c calling line. Remember you can do arithmetic
on the result with SET /A if you're in the Win95cmd subroutine.

--
(pp) William Allen

Note for general interest:
Win95cmd.exe is a Microsoft batch enhancer for Windows 95/98/ME
users who are interested in learning and using some of the enhanced
batch language features in Win2000 (similar enhanced Batch features
are present in Windows XP). The big advantage of using Win95cmd
over third party Batch utilities is that it enables you to learn and use
(in Windows 9x) elements of the Batch syntax that can also be used
in Win2000 and WinXP should you go on to use/learn those OSes.

Win95cmd.exe file is available free as a single small ZIP from:
http://www.neuro.gatech.edu/users/cwilson/cygutils/unversioned/consize/

For general information about using it in Windows 95/98/ME and
syntax examples, see post:

Win95cmd Batch enhancer for Windows 95/98/ME users
http://groups.google.com/groups?selm=a04ecl$isbjh$1...@ID-55970.news.dfncis.de
Date: 23 Dec 2001

and for use of Win95cmd in Batch arithmetic, see post:

Timo Salmi

unread,
Feb 12, 2002, 4:09:44 AM2/12/02
to
Todd Vargo <todd...@yahoo.com> wrote in news:alt.msdos.batch
> "pchelp" <pch...@pc-help.org> wrote in news:alt.msdos.batch

> > I'll take the [sweep] file off my site. It was only there to help with the


> > topic at hand. I welcome your reminder; I know you want to see
> > respectful treatment of others' works.

> You could replace it with the official file or even link to it.

Remaining on the subject of the sweep package

ftp://garbo.uwasa.fi/pc/pcmagvol/vol4n24.zip

and the PC-Magazine files in general. The packages are named
according to the volume of appearance. That is not very informative
for finding the specific utilities. And there are some really
vintage ones in that collection. To alleviate the situation there
is the zip content index file

37837 Jun 11 1997 ftp://garbo.uwasa.fi/pc/pcmagvol/0pcmagvl.zip
0pcmagvl.zip .zip files contents in /pc/pcmagvol directory

The relevant directories at Garbo when using WWW are

http://garbo.uwasa.fi/pc/pcmagvol.html
http://garbo.uwasa.fi/pc/pcmagutl.html

Walter Briscoe

unread,
Feb 12, 2002, 7:03:22 AM2/12/02
to
In article <a45gl1$1c94t9$1...@ID-55970.news.dfncis.de> of Sun, 10 Feb 2002
10:04:37 in alt.msdos.batch, William Allen
<NgR...@mayfly13.fsnet.co.uk> writes
[snip]

I found this code did not work for me.
I extracted the code to try.bat, altered BASE to reference C:\WFB\BIN
and tried the code.
On Windows 95, I got
D:\wfb> ver

Windows 95. [Version 4.00.1111]


D:\wfb> find "SET BASE" try.bat

---------- try.bat
SET BASE=C:\wfb\bin
SET BASE=

D:\wfb> try
File not found - NUL
D:\wfb> command/y/ctry
try [Enter=Y,Esc=N]?Y
ECHO OFF [Enter=Y,Esc=N]?Y
IF (GOTO:)==() (Subroutine handler) [Enter=Y,Esc=N]?Y
SET BASE=C:\wfb\bin [Enter=Y,Esc=N]?Y
ECHO.@PROMPT CALL try GOTO: _FSCAN >C:\WINDOWS\TEMP.\FL.BAT
[Enter=Y,Esc=N]?Y
xcopy C:\wfb\bin\NUL C:\ /l/n/s|find /v " ">>C:\WINDOWS\TEMP.\FL.BAT
[Enter=Y,
Esc=N]?Y
File not found - NUL
ECHO.@ECHO OFF>>C:\WINDOWS\TEMP.\FL.BAT [Enter=Y,Esc=N]?^C

D:\wfb> dir %temp%\fl.bat

Volume in drive C has no label
Volume Serial Number is 0C32-1BD7
Directory of C:\WINDOWS\TEMP

FL BAT 32 12/02/02 11:24 FL.BAT
1 file(s) 32 bytes
0 dir(s) 390,299,648 bytes free

D:\wfb> type %temp%\fl.bat
@PROMPT CALL try GOTO: _FSCAN

D:\wfb> xcopy c:\wfb\bin\nul c:\ /l/n/s
File not found - nul
0 File(s)

D:\wfb>

I conclude the xcopy usage is version variable.

On W98SE, the code looped and used approximately 100% of the CPU.
When I interrupted the batch, It produced the same name an infinite
number of times. When I interrupted again, I got a terminate batch
question.

C:\wfb> ver

Windows 98 [Version 4.10.2222]


C:\wfb> find "SET BASE" try.bat

---------- try.bat
SET BASE=C:\wfb\bin
SET BASE=

C:\wfb> try

C:\wfb>
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260.TMP
VIM8260^C

Terminate batch job (Y/N)?y

C:\wfb> sed 8q < %temp%\pf.bat

CALL try GOTO: _FSCAN NUL

CALL try GOTO: _FSCAN
CALL try GOTO: _FSCAN
CALL try GOTO: _FSCAN
CALL try GOTO: _FSCAN
CALL try GOTO: _FSCAN

C:\wfb>

I am unable to diagnose this and would appreciate help.
('twould probably be better done by email until we have a diagnosis.)

My usual diagnostic technique of %command%/y/cscript is foiled by your
%comspec% nul /c script line. The technique is old, but new to me.
(First used in passing by Tom Lavedas on 1996/04/22.) %comspec% is
started and runs script with both input and output connected to NUL.
i.e. No input is taken and output is scrapped.

I love the filtering of error messages to NUL from commands written to a
.BAT for later execution!
--
Walter Briscoe

William Allen

unread,
Feb 12, 2002, 8:31:37 AM2/12/02
to
"Walter Briscoe" wrote in message
...snip

> I conclude the xcopy usage is version variable.

No. The XCOPY part works the same. A quick look shows it's
the different treatment of Bouncing off the Prompt in Windows 98

> On W98SE, the code looped and used approximately 100% of the CPU.
> When I interrupted the batch, It produced the same name an infinite
> number of times. When I interrupted again, I got a terminate batch
> question.

Thanks for pointing this out. It's is a version difference
with Win98 compared with Win95. The difference appears
to be the different treatment of a batch file that contains
the command: NUL

For example If you create a batch file, TEST.BAT, consisting only of one line:
NUL

and "bounce it off the prompt" it in Windows 95 in a child shell:
command /c TEST.BAT

it just gives bad command or file name, as you would expect.

However, in Windows 98, the same command line
command /c TEST.BAT

loops and runs into trouble. Thanks again for pointing this
out. I'll look at it further when time permits. Feel free to
contact me by email if you want a diagnostic version of
the code to show more clearly what's happening.

--
(pp) William Allen


William Allen

unread,
Feb 12, 2002, 9:17:10 AM2/12/02
to
"William Allen" wrote in message
...snip

> Thanks for pointing this out. It's is a version difference
> with Win98 compared with Win95. The difference appears
> to be the different treatment of a batch file that contains
> the command: NUL
...snip

> I'll look at it further when time permits.

Found the time<G>.

As I say, the problem is that a Batch file containing a line:
NUL
or indeed
C:\NUL
in Win98 gives a problem, but not in Win95 where it's just
treated as a bad command or file name.

This workaround removes the NUL line in the XCOPY listing
and uses NULX instead, which will do for this task. This
version tests out in Win98 SE here (the previous version
fails, and we can reproduce your findings). Note that the
C:\FOLDER tree needs to exist or you'll get "file not found"
errors.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

SET BASE=C:\FOLDER

ECHO.@PROMPT CALL %0 GOTO: _FSCAN >%TEMP%.\FL.BAT

ECHO.NULX>>%TEMP%.\FL.BAT
xcopy %BASE%\NUL C:\ /l/n/s|find /v " "|find "\NUL">>%TEMP%.\FL.BAT
ECHO.@ECHO OFF>>%TEMP%.\FL.BAT
%COMSPEC% NUL /c %0 GOTO: _PREFIX %TEMP%.\FL.BAT


ECHO.EXIT|%COMSPEC%/e:4096/k PROMPT $N:$_CD $P$_:>%TEMP%.\H.BAT
FOR %%F IN (CALL DEL) DO %%F %TEMP%.\PF.BAT
DEL %TEMP%.\H.BAT

SET BASE=

GOTO EOF (=Subroutine code follows=)
:_FSCAN
%BASE%\
CD %BASE%\%3\..

:: This next line is merely to show that we traverse each folder
CD


:: This FOR IN DO loop executed in BASE and all subfolders of BASE
FOR %%F IN (*.TMP) DO ECHO.%%F
CALL %TEMP%.\H.BAT

GOTO EOF (=Subroutine code follows=)
:_PREFIX
%COMSPEC%/c %3>%TEMP%.\PF.BAT
DEL %3

:EOF (End-of-file)

====End cut-and-paste (omit this line)

Cut-and-paste text between the ==== lines into file with extension .BAT
(and suitable base name). Lines that don't begin with two spaces have
wrapped accidentally. The code sample is purely for demonstration and

study purposes. It was written/tested in the Win98 GUI.

--
(pp) William Allen


Walter Briscoe

unread,
Feb 12, 2002, 11:50:04 AM2/12/02
to
In article <a4b87m$1di63u$1...@ID-55970.news.dfncis.de> of Tue, 12 Feb 2002
14:17:10 in alt.msdos.batch, William Allen
<NgR...@mayfly13.fsnet.co.uk> writes
[snip]

>As I say, the problem is that a Batch file containing a line:
>NUL
>or indeed
>C:\NUL
>in Win98 gives a problem, but not in Win95 where it's just
>treated as a bad command or file name.
>
>This workaround removes the NUL line in the XCOPY listing
>and uses NULX instead, which will do for this task. This
>version tests out in Win98 SE here (the previous version
>fails, and we can reproduce your findings). Note that the
>C:\FOLDER tree needs to exist or you'll get "file not found"
>errors.
[snip]
A big improvement! On W98SE, It seems not to sweep a folder with no
children. On W95, it is now correct AFAIK.
--
Walter Briscoe

William Allen

unread,
Feb 12, 2002, 12:59:30 PM2/12/02
to
"William Allen" wrote in message
> "William Allen" wrote in message
> ...snip
> > Thanks for pointing this out. It's is a version difference
> > with Win98 compared with Win95. The difference appears
> > to be the different treatment of a batch file that contains
> > the command: NUL
> ...snip
> > I'll look at it further when time permits.
>
> Found the time<G>.
>
> As I say, the problem is that a Batch file containing a line:
> NUL
> or indeed
> C:\NUL
> in Win98 gives a problem, but not in Win95 where it's just
> treated as a bad command or file name.

Unsurprisingly, other device names, such as AUX, PRN
also produce the looping "batch file missing" behaviour in
Win98, but not in Win95.

--
(pp) William Allen


Dr John Stockton

unread,
Feb 12, 2002, 7:20:12 AM2/12/02
to
JRS: In article <a4agkn$1dmdb7$3...@ID-55970.news.dfncis.de>, seen in
news:alt.msdos.batch, William Allen <NgR...@mayfly13.fsnet.co.uk> wrote
at Tue, 12 Feb 2002 07:24:11 :-

>
>Note for general interest:
>Win95cmd.exe is a Microsoft batch enhancer for Windows 95/98/ME
>users who are interested in learning and using some of the enhanced
>batch language features in Win2000 (similar enhanced Batch features
>are present in Windows XP). The big advantage of using Win95cmd
>over third party Batch utilities is that it enables you to learn and use
>(in Windows 9x) elements of the Batch syntax that can also be used
>in Win2000 and WinXP should you go on to use/learn those OSes.
>
>Win95cmd.exe file is available free as a single small ZIP from:
>http://www.neuro.gatech.edu/users/cwilson/cygutils/unversioned/consize/
>
>For general information about using it in Windows 95/98/ME and
>syntax examples, see post:
>
>Win95cmd Batch enhancer for Windows 95/98/ME users
>http://groups.google.com/groups?selm=a04ecl$isbjh$1...@ID-55970.news.dfncis.de
>Date: 23 Dec 2001
>
>and for use of Win95cmd in Batch arithmetic, see post:
>Batch arithmetic with the Win95cmd Batch enhancer
>http://groups.google.com/groups?selm=9vdkh4$efe02$1...@ID-55970.news.dfncis.de
>Date: 14 Dec 2001

I think you miss, from the point of view of the average user, an
essential point with regard to Win95cmd.exe.

That is EITHER that one merely needs to put a copy of the EXE on the
Path, and that doing so changes *nothing* other than that one can now
type "win95cmd" and one is then, until "exit", within a new CP; OR is
whatever is, instead of that, true.

Many users will be willing to try new facilities only if assured that
everything else will still work, and that their tests will do no harm.
It may be that, for example, one can have a couple of DOS boxes and, in
one, execute SET COMSPEC=...WIN95CMD.EXE, upgrading one box; IF SO, this
could be a good way to test.

I am reminded of the time that I asked "Is there a way to change the
font in X & Y input lines of screen Z in product Q?" - the advice given
would have that effect; but it would also, intolerably, change that font
throughout Windows.



--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©

Web <URL: http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (SonOfRFC1036)
Do not Mail News to me. Before a reply, quote with ">" or "> " (SonOfRFC1036)

William Allen

unread,
Feb 12, 2002, 1:25:36 PM2/12/02
to
"Dr John Stockton" wrote in message
...snip

> I think you miss, from the point of view of the average user, an
> essential point with regard to Win95cmd.exe.
>
> That is EITHER that one merely needs to put a copy of the EXE on the
> Path,

You've missed the point. That's all I ever do to use it
in all the scripts I post. Try reading before posting.

--
(pp) William Allen


Secret_Doom

unread,
Feb 13, 2002, 1:02:37 AM2/13/02
to
"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message news:<a4agkn$1dmdb7$3...@ID-55970.news.dfncis.de>...
(snip)

>
> Also try, for example
> if /?
>
> and see that you can use comparisons such as:
> EQU - equal
> NEQ - not equal
> LSS - less than
> LEQ - less than or equal
> GTR - greater than
> GEQ - greater than or equal
>
(snip)

>
> Note the following extracts from SET /? help:
>
> %CD% - expands to the current directory string.
> %DATE% - expands to current date using same format as DATE command
> %TIME% - expands to current time using same format as TIME command
> %RANDOM% - expands to a random decimal number between 0 and 32767.
> %ERRORLEVEL% - expands to the current ERRORLEVEL value
>
> Note that ERRORLEVELs are lost when you transfer control
> to a child shell, or return to a parent shell.
>
(snip)

Greater than? Less than? *OUCH* !
Those variables are like gold man. I miss very much sometimes the
%errorlevel% in Win98.
I also noticed the FOR/N, which allows you to create a set of numbers,
specifying the begin, end and how are the numbers going to change!

I don't understand what you mean by "child shell" and "parent
shell"... You mean by opening new commmand prompts inside the current
command prompt ?

William Allen

unread,
Feb 13, 2002, 3:51:35 AM2/13/02
to
"Secret_Doom" wrote in message
...snip
> I don't understand what you mean by "child shell" and "parent
> shell"... You mean by opening new commmand prompts inside the current
> command prompt ?

Yes, but they are best thought of as parent and child because
of the way environment changes are inherited parent to child,
but not child to parent.

This demo shows the way our team here think and talk about
command shells and variable inheritance.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

CLS
ECHO. We are in the main or parent shell for this script.
ECHO. If I set a variable TEST to "ParentShellString" it
ECHO. will be inherited by any child shell I open
SET TEST=ParentShellString
ECHO. TEST is now %TEST%
ECHO.
ECHO. Extract from SET listing...
SET | find "TEST=" | find /v "CMDLINE"
ECHO.
ECHO. Press [Return] to continue...
PAUSE>NUL
ECHO.
ECHO. Now we'll recall ourselves in a child shell with the command:
ECHO. %COMSPEC% /c %0 GOTO: _SUBR
ECHO.
ECHO. Press [Return] to continue...
PAUSE>NUL
%COMSPEC% /c %0 GOTO: _SUBR
CLS
ECHO. We've now returned to the parent shell.
ECHO. TEST is again %TEST%
ECHO.
ECHO. Extract from SET listing...
SET | find "TEST=" | find /v "CMDLINE"
ECHO.
ECHO.
ECHO. That's all folks.
SET TEST=

GOTO EOF (=Subroutine code follows=)

:_SUBR (Usage: CALL %0 GOTO: _SUBR)
CLS
ECHO. Now we're in the child shell. We've inherited variable TEST
ECHO. TEST is %TEST%
ECHO.
ECHO. Extract from SET listing...
SET | find "TEST=" | find /v "CMDLINE"
ECHO.
ECHO. We can change TEST to "ChildShellString" with a SET command
SET TEST=ChildShellString
ECHO. That's done, and TEST is now %TEST%
ECHO.
ECHO. Extract from SET listing...
SET | find "TEST=" | find /v "CMDLINE"
ECHO.
ECHO.
ECHO. But the value of TEST in our parent shell (from which we
ECHO. were called) is still as it was before, because changes
ECHO. to variables in the child shell don't affect the parent shell
ECHO.
ECHO. Press [Return] to end Subroutine and return to the parent shell
PAUSE>NUL

:EOF (End-of-file)

====End cut-and-paste (omit this line)
Cut-and-paste text between the ==== lines into file with extension .BAT
(and suitable base name). Lines that don't begin with two spaces have
wrapped accidentally. The code sample is purely for demonstration and

study purposes. It was written/tested in the Win9x GUI.

--
(pp) William Allen


Dr John Stockton

unread,
Feb 13, 2002, 1:22:03 PM2/13/02
to
JRS: In article <a4bmol$1e8m5m$1...@ID-55970.news.dfncis.de>, seen in

news:alt.msdos.batch, William Allen <NgR...@mayfly13.fsnet.co.uk> wrote
at Tue, 12 Feb 2002 18:25:36 :-

You do not say it explicitly in your pseudo-signature. To be useful,
one needs to be able to look at things from the point of view of one who
is newly-arrived, and who may rightly be uncertain about installation of
new components into Windows.



--
© John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME. ©

Secret_Doom

unread,
Feb 13, 2002, 11:32:42 PM2/13/02
to
"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message news:<a4d9h3$1e2d0u$1...@ID-55970.news.dfncis.de>...

>
> Yes, but they are best thought of as parent and child because
> of the way environment changes are inherited parent to child,
> but not child to parent.
>
> This demo shows the way our team here think and talk about
> command shells and variable inheritance.
>

I see, that's what I thought it was, and that was how I thought things would go.
Nice demo!

0 new messages