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

IF command problem

29 views
Skip to first unread message

gwen

unread,
Mar 26, 2002, 1:20:36 PM3/26/02
to
Hi, I'm trying to learn the IF command but I can't get the following demo
batch file to work. The folder "test" does not exist, but yet the batch
file always echoes "folder exists" and the test folder never gets created.

@echo off
if exist c:\windows\test
goto end
md c:\windows\test
move notes.txt c:\windows\test
:end
echo folder exists.

Thanks in advance for your help.

gwen


William Allen

unread,
Mar 26, 2002, 2:08:15 PM3/26/02
to
"gwen" wrote in message

IF EXIST is for files, not folders. The normal way to check
whether or not a folder exists is to test for the NUL file/device
which formally exists in all folders that themselves exist.

Syntax is:

IF EXIST PathToFolder\NUL GOTO Label

So, try something like this:

====Begin cut-and-paste (omit this line)
@ECHO OFF
:: Check whether or not NUL device exists in Folder
IF EXIST C:\WINDOWS\TEST\NUL GOTO FOLDER-OK

:: Make the folder
MD C:\WINDOWS\TEST
GOTO DO-MOVE

:FOLDER-OK
ECHO. Folder exists

:DO-MOVE
:: Do the move
MOVE NOTES.TXT C:\WINDOWS\TEST

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

--
(pp) William Allen


gwen

unread,
Mar 26, 2002, 4:06:37 PM3/26/02
to
Thank you! It worked perfectly - I didn't know about if exist being only
for files Also, I don't know if this is impossible with a bat file. but is
there any
way to create a bat file that would allow the user to move the folder stuff
to test\mystuff(as in the below demo) more than one time before getting the
"task completed" echo?. The ideal would be that the bat file could be
executed 2 times silently and each time a folder named stuff would be moved
to test, but on the 3rd execution, -the "task completed" echo would appear,
and no more. Note - the user is not aware of where the folder is being
moved. The user simply executes the command to automaticlly move the stuff
folder.
I was thinking maybe with conditional calls to other bat files and maybe
deleting each one after execution except for the last one that would echo
the "task completed" message?.

gwen

@echo off
if exist c:\windows\test\nul goto end
md c:\windows\test
move c:\windows\desktop\stuff c:\windows\test\mystuff
cls
exit
:END
echo task completed

thanks again for all your help.

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

William Allen

unread,
Mar 26, 2002, 5:42:49 PM3/26/02
to
"gwen" wrote in message

> Thank you! It worked perfectly - I didn't know about if exist being only
> for files Also, I don't know if this is impossible with a bat file. but is
> there any
> way to create a bat file that would allow the user to move the folder stuff
> to test\mystuff(as in the below demo) more than one time before getting the
> "task completed" echo?. The ideal would be that the bat file could be
> executed 2 times silently and each time a folder named stuff would be moved
> to test, but on the 3rd execution, -the "task completed" echo would appear,
> and no more. Note - the user is not aware of where the folder is being
> moved. The user simply executes the command to automaticlly move the stuff
> folder.
> I was thinking maybe with conditional calls to other bat files and maybe
> deleting each one after execution except for the last one that would echo
> the "task completed" message?.

It sounds like you simply need to use more GOTO Label flow control
within the one Batch file. You can use many labels and route the
logical flow around them if a particular task is found to be completed.

Perhaps something like this may be the sort of thing you want to do.

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: This is the first task
IF EXIST C:\WINDOWS\TEST\NUL GOTO JOB1-DONE
MD C:\WINDOWS\TEST
:: Optionally use redirection to >NUL to silence the move report
move C:\WINDOWS\DESKTOP\STUFF C:\WINDOWS\TEST\MYSTUFF>NUL

:JOB1-DONE
:: This is the second task
IF EXIST C:\WINDOWS\TEST2\NUL GOTO JOB2-DONE
MD C:\WINDOWS\TEST2
:: Optionally use redirection to >NUL to silence the move report
move C:\WINDOWS\DESKTOP\STUFF2 C:\WINDOWS\TEST2\MYSTUFF>NUL

:JOB2-DONE
:: This is the third task
IF EXIST C:\WINDOWS\TEST3\NUL GOTO JOB3-DONE
MD C:\WINDOWS\TEST3
:: Optionally use redirection to >NUL to silence the move report
move C:\WINDOWS\DESKTOP\STUFF3 C:\WINDOWS\TEST3\MYSTUFF>NUL

:JOB3-DONE
ECHO. All tasks completed

:: Allow five seconds delay for the TASK message to be read
REM | choice /c:delay /td,5>NUL

:: Clear the screen so the Window will close automatically
CLS

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

The 5-second delay command:
REM | choice /c:delay /td,5>NUL

can be adjusted from 1 to 99 seconds instead of 5 as above. It simply
exploits a feature of the CHOICE command to pause for a set number
of seconds, then resume.

--
(pp) William Allen


gwen

unread,
Mar 26, 2002, 9:36:31 PM3/26/02
to
many thanx William - that did it - I just had to edit it a bit to make it
work.
The file would create all 3 folders on first execution, so I added the EXIT
command between each set and it worked.
And I like that REM | choice /c:delay /td,5>NUL command you added.
Didn't know that one.

gwen

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

news:a7qui0$ngblj$1...@ID-55970.news.dfncis.de...


"gwen" wrote in message
> Thank you! It worked perfectly - I didn't know about if exist being
only
> for files Also, I don't know if this is impossible with a bat file.
but is> there any> way to create a bat file that would allow the user to
move the folder

stuffo test\mystuff(as in the below demo) more than one time before getting
th "task completed" echo?. The ideal would be that the bat file could be


> > executed 2 times silently and each time a folder named stuff would be

move to test, but on the 3rd execution, -the "task completed" echo would


appear, and no more. Note - the user is not aware of where the folder is
being
> moved. The user simply executes the command to automaticlly move the
stuff folder. I was thinking maybe with conditional calls to other bat
files and
maybe> deleting each one after execution except for the last one that would

echothe "task completed" message?.

Timo Salmi

unread,
Mar 27, 2002, 12:07:26 AM3/27/02
to
In article <a7qe6v$9si$1...@onlink3.onlink.net>, gwen <gw...@graffitti.net> wrote:
> Hi, I'm trying to learn the IF command but I can't get the following demo
> batch file to work. The folder "test" does not exist, but yet the batch
> file always echoes "folder exists" and the test folder never gets created.
> if exist c:\windows\test

Use FIND and errorlevel instead of the exist test. An example of the
method from

218093 Mar 1 2002 ftp://garbo.uwasa.fi/pc/link/tsbat.zip
tsbat.zip Useful batch files and tricks, linked from /pc/ts, T.Salmi

This avoids confusing the existence of a directory with the
existence of a file. I will also work for s CD-ROM, which usually
otherwise causes problems. Furthermore, the testing you use is a bit
off. You should have tried if exist c:\windows\test\nul

@echo off
::
if "%1"=="" goto _usage
::
dir %1|find " Directory of "|find /i "%1">nul
set found_=yes
if errorlevel==2 set found_=no
if errorlevel==1 set found_=no
::
if "%found_%"=="yes" echo %1 is a directory
if "%found_%"=="no" echo %1 is not a directory
goto _end
::
:_usage
echo Usage: %0 [Target]
::
:_end

For more, see the said item #4.

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

Benny Pedersen

unread,
Mar 27, 2002, 12:07:55 AM3/27/02
to

"gwen" <gw...@graffitti.net> wrote news:a7rb8p$b62$1...@onlink3.onlink.net...

Hi,

The [Ctrl]+[C] or [Ctrl]+[Break] key press while delaying
created/left behind two of those AFDEBDFD files in the TEMP folder.

This won't,

===
@ECHO OFF
IF GOTO:Delay == %1 %1 ==SUB==
%1 %COMSPEC%/C%0 GOTO:Delay
IF EXIST %temp%.\????????. FOR %%8 in (A B C D E F G H I J K L M N O P) do %COMSPEC%/CFOR %%F in (%temp%.\???????%%8.) do DEL %%F
GOTO EOF

:Delay
REM|choice/c~/t~,04>NUL
:EOF
===

Benny Pedersen.
PS. Who can you do it briefer? ;-)

Benny Pedersen

unread,
Mar 27, 2002, 12:51:03 AM3/27/02
to

"Benny Pedersen" <b.ped...@get2net.dk> wrote news:Bsco8.1$JQ3...@news.get2net.dk...

>
> "gwen" <gw...@graffitti.net> wrote news:a7rb8p$b62$1...@onlink3.onlink.net...
> > many thanx William - that did it - I just had to edit it a bit to make it
> > work.
> > The file would create all 3 folders on first execution, so I added the EXIT
> > command between each set and it worked.
> > And I like that REM | choice /c:delay /td,5>NUL command you added.

> The [Ctrl]+[C] or [Ctrl]+[Break] key press while delaying


> created/left behind two of those AFDEBDFD files in the TEMP folder.
>
> This won't,
>
> ===
> @ECHO OFF
> IF GOTO:Delay == %1 %1 ==SUB==
> %1 %COMSPEC%/C%0 GOTO:Delay
> IF EXIST %temp%.\????????. FOR %%8 in (A B C D E F G H I J K L M N O P) do %COMSPEC%/CFOR %%F in (%temp%.\???????%%8.) do DEL
%%F
> GOTO EOF
>
> :Delay
> REM|choice/c~/t~,04>NUL
> :EOF
> ===
>
> Benny Pedersen.
> PS. Who can you do it briefer? ;-)


BTW. To join the competition, make sure that none of the following
3 files would be included,
ABCDEFGHA (9 long without extension)
AAAAAAAA.TXT (8 long with an extension)

Benny Pedersen,
PS. Maybe this is better,

[A]??????[A...P].
[B]??????[A...P].


@ECHO OFF
%1 %COMSPEC%/C%0 GOTO:Delay>NUL
FOR %%1 in (A B) do %COMSPEC%/CFOR %%8 in (A B C D E F G H I J K L M N O P) do %COMSPEC%/CFOR %%0 in (%temp%.\%%1??????%%8.) do
DEL/P %%0
FOR %%c in (GOTO:EOF CLS) do %%c

:Delay
REM|choice/c~/t~,03
:EOF

REM --Note: Remove the P in the DEL/P


William Allen

unread,
Mar 27, 2002, 3:50:27 AM3/27/02
to
"Benny Pedersen" wrote in message
...snip

> The [Ctrl]+[C] or [Ctrl]+[Break] key press while delaying
> created/left behind two of those AFDEBDFD files in the TEMP folder.

That doesn't happen here, but if you prefer you
can run the delay in a separate process. You
can still interrupt the delay by pressing [Ctrl [C]]
in the main process, but the CHOICE pipe command
runs to completion in a separate, minimized window,
which then closes automatically after the delay.

====Begin cut-and-paste (omit this line)
@ECHO OFF

IF (GOTO:)==(%1) %1%2 (Subroutine handler)

start /w /m %0 GOTO: _DELAY 10 (=seconds to delay)

GOTO EOF (=Subroutine code follows=)
:_DELAY (Usage: start /w /m %0 GOTO: _DELAY TimeSecs(1-99))
REM | choice /c:delay /td,%3>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


Benny Pedersen

unread,
Mar 27, 2002, 4:34:27 AM3/27/02
to

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote news:a7s16o$nldqi$1...@ID-55970.news.dfncis.de...

> > The [Ctrl]+[C] or [Ctrl]+[Break] key press while delaying
> > created/left behind two of those AFDEBDFD files in the TEMP folder.
>
> That doesn't happen here,
...[snipped].


Hmmm??? I'm using Win98 and each time I tried this,
I got two junk files:

REM | choice /C:delay /T:d,5 > NUL

but with a %COMSPEC%/C I didn't got any junk files:

REM | %COMSPEC% /C choice /C:delay /T:d,5 > NUL

So, maybe the difference is our OS?

Benny,
PS. I just found the %COMSPEC%/C solution few minutes ago,
(Subject YAHOOOO) so, I have now updated that new
information on my Webpage. :-)


> can run the delay in a separate process. You
> can still interrupt the delay by pressing [Ctrl [C]]
> in the main process, but the CHOICE pipe command
> runs to completion in a separate, minimized window,
> which then closes automatically after the delay.
>
> ====Begin cut-and-paste (omit this line)
> @ECHO OFF
> IF (GOTO:)==(%1) %1%2 (Subroutine handler)
>
> start /w /m %0 GOTO: _DELAY 10 (=seconds to delay)
>
> GOTO EOF (=Subroutine code follows=)
> :_DELAY (Usage: start /w /m %0 GOTO: _DELAY TimeSecs(1-99))
> REM | choice /c:delay /td,%3>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

See notes above.


Benny Pedersen

unread,
Mar 27, 2002, 4:56:03 AM3/27/02
to

"Timo Salmi" <t...@UWasa.Fi> wrote news:a7rk2e$p...@poiju.uwasa.fi...

Hi,

set found_=yes
if errorlevel==2 set found_=no
if errorlevel==1 set found_=no

Since errorlevel 2 would be included in the testing for
errorlevel 1, then this could be written as two lines:

set found_=yes
if errorlevel 1 set found_=no

or as this, (one line):

for %%c in (no yes) do if not errorlevel 9%%c set found_=%%c

Benny Pedersen,
PS. You probably already knew all that but anyway...
BTW. To examine an errorlevel, use the B-Levels.bat,
http://2dos.homepage.dk/batutil/NEWS4.HTM#bennylevel

William Allen

unread,
Mar 27, 2002, 4:54:44 AM3/27/02
to
"Benny Pedersen" wrote in message
>
> "William Allen" wrote

> > > The [Ctrl]+[C] or [Ctrl]+[Break] key press while delaying
> > > created/left behind two of those AFDEBDFD files in the TEMP folder.
> >
> > That doesn't happen here,
> ...[snipped].
>
>
> Hmmm??? I'm using Win98 and each time I tried this,
> I got two junk files:
>
> REM | choice /C:delay /T:d,5 > NUL
>
> but with a %COMSPEC%/C I didn't got any junk files:
>
> REM | %COMSPEC% /C choice /C:delay /T:d,5 > NUL
>
> So, maybe the difference is our OS?

Apparently not (capture from Win98 partition on my partner's machine):

============Screen capture Windows 98
C:\WORK>dir %temp% /b

C:\WORK>ver

Windows 98 [Version 4.10.2222]


C:\WORK>echo.|time
Current time is 9:50:03.43
Enter new time:

C:\WORK>rem interrupting with [Ctrl [C]] | choice /c:delay /td,99>nul

C:\WORK>echo.|time
Current time is 9:50:07.44
Enter new time:

C:\WORK>dir %temp% /b

C:\WORK>
============End screen capture

--
(pp) William Allen


gwen

unread,
Mar 27, 2002, 9:30:02 AM3/27/02
to
Thanx for that useful info
I am still very much a beginner but the IF command worked fine after using
the NUL.
I have one other problem though.
In these 2 demo files, I want the first one to echo the Not Permitted
message anytime a user tries to execute the file more than once, even though
the TEST folder will be deleted when the user decides to excute the second
file.

FILE ONE
@ECHO OFF
IF EXIST C:\WINDOWS\TEST\NUL GOTO OVER
md C:\WINDOWS\SYSTEM\TEST
move c:\windows\desktop\%1 "C:\WINDOWS\TEST\%1>NUL
exit
:OVER
ECHO Not Permitted

FILE TWO
@ ECHO OFF
move c:\windows\test\%1 c:\windows\desktop\%1>NUL
deltree /y c:\windows\test
cls

An acceptable solution if possible would be if the IF EXIST command for the
TEST folder could be changed after the first or second file is clicked to
an IF EXIST for some default Windows folder - ei Windows itself (if
c:\windows exists, echo Not Permitted) ?
The bottom line is that the user should only be allowed to move one folder,
later restore it, and then receive a Not Permitted message anytime the first
file is clicked again - but deleting that first file is not an option unless
it can be silently replaced with another file of the same name that would
only produce a Not Permitted message.

Any ideas on how to do this would be most appreciated!


gwen


"Timo Salmi" <t...@UWasa.Fi> wrote in message
news:a7rk2e$p...@poiju.uwasa.fi...

William Allen

unread,
Mar 27, 2002, 11:16:23 AM3/27/02
to
"gwen" wrote in message

> Thanx for that useful info
> I am still very much a beginner but the IF command worked fine after using
> the NUL.
> I have one other problem though.
> In these 2 demo files, I want the first one to echo the Not Permitted
> message anytime a user tries to execute the file more than once, even though
> the TEST folder will be deleted when the user decides to excute the second
> file.

You could store a simple "count" of how many times the
File One was used, say X for once XX for twice and so on in
a file. Decide on a file name and location. In the demo,
I've used C:\{CHECK}.BAT but you can choose something
else if you wish. Best to make it a .BAT file so you can
recover the stored data trivially.

Additionally, you need to give users some result message
for any Batch file run and allow them time to read it. So
I've altered the flow to ensure there is always 5 seconds
for the user to see TASK message report or error message.

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: This is File One

IF ()==(%1) GOTO E_FOLDER

:: First check how many times we've been used
SET COUNT=
IF EXIST C:\{CHECK}.BAT CALL C:\{CHECK}.BAT
IF (%COUNT%)==(X) GOTO OVER

:: Do the folder creation and move


IF EXIST C:\WINDOWS\TEST\NUL GOTO OVER

MD C:\WINDOWS\SYSTEM\TEST


move c:\windows\desktop\%1 "C:\WINDOWS\TEST\%1>NUL

ECHO. Folder %1 moved

:: Append X to COUNT and store in C:\{CHECK}.BAT for next time
SET COUNT=X%COUNT%
ECHO.SET COUNT=%COUNT%>C:\{CHECK}.BAT
SET COUNT=
GOTO OUT

:OVER
ECHO. Not Permitted (you've used this script at least once already)
GOTO OUT

:E_FOLDER
ECHO. Usage is: %0 FolderName
ECHO. You didn't specify a folder
ECHO.

:OUT
:: Allow 5 seconds for user to see any messages


REM | choice /c:delay /td,5>NUL

:: Clear the screen so window will close automatically
CLS

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

In general, the count check line:

IF (%COUNT%)==(X) GOTO OVER

can be changed to permit say, a maximum of three uses:
IF (%COUNT%)==(XXX) GOTO OVER

and analogously for other limits.

Important point to note with SETting variables. In lines such as

SET COUNT=
SET COUNT=X%COUNT%

_make_sure_ there are _NO_ trailing [Space]s or other
whitespace characters at the end of the line or they are
loaded into the variables and may cause errors.

--
(pp) William Allen


gwen

unread,
Mar 27, 2002, 4:16:29 PM3/27/02
to

I was impressed by how that worked - sure am learning a lot from you.
I added a command in File 2 to deltree the Test folder upon the user
restoring the moved folder and works just fine. Only one small concern is
that (check.bat) may be found. With the other bat files tampering is
prevented by converting them to com files.
Is there anyway, that I can make this work by creating a fixed com file
containing SET=XX that I can place in the command folder and have File one
call it each time?
If not, I'll just try to place the bat file in some less obvious location.
Thanks again for all your input and help - most grateful

gwen

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

news:a7ss2n$mft7n$1...@ID-55970.news.dfncis.de...

> In general, the count check line:
>
> IF (%COUNT%)==(X) GOTO OVER
>
> can be changed to permit say, a maximum of three uses:
> IF (%COUNT%)==(XXX) GOTO OVER

> and analogously for other limits.
>
> Important point to note with SETting variables. In lines such as

> SET COUNT=
> SET COUNT=X%COUNT%

> _make_sure_ there are _NO_ trailing [Space]s or other
> whitespace characters at the end of the line or they are
> loaded into the variables and may cause errors.

> (pp) William Allen


Benny Pedersen

unread,
Mar 27, 2002, 5:10:51 PM3/27/02
to

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote news:a7s500$npqf4$1...@ID-55970.news.dfncis.de...


[Version 4.10.1998].

@echo off
REM|choice Press [Ctrl]+[C] or [Ctrl]+[Break]

Benny,

BTW. strange problem?

Junk files begins with A early morning but begins with
B in the evening.

BGCPABDC

IF EXIST %temp%.\B*. ECHO Goto sleep

Can you calculate the time of such a junk file?


William Allen

unread,
Mar 27, 2002, 6:16:00 PM3/27/02
to
"gwen" wrote in message

>
> I was impressed by how that worked - sure am learning a lot from you.
> I added a command in File 2 to deltree the Test folder upon the user
> restoring the moved folder and works just fine. Only one small concern is
> that (check.bat) may be found. With the other bat files tampering is
> prevented by converting them to com files.
> Is there anyway, that I can make this work by creating a fixed com file
> containing SET=XX that I can place in the command folder and have File one
> call it each time?
> If not, I'll just try to place the bat file in some less obvious location.
> Thanks again for all your input and help - most grateful

The whole point of Batch files is that you _can_ very quickly
"tamper" with them (tamper = edit). Quite simply that IS their
entire rationale. If you want COM or EXE files, why not just
write programs in the first place?

That said, you could "disguise" the check file as a VXD in
C:\WINDOWS\SYSTEM for example USR32.VXD (there is no
such file). Most people will ignore VXDs, or leave them alone.
To use the check file you temporarily rename it to a BAT file
(which, in format, it really is).

====Begin cut-and-paste (omit this line)
@ECHO OFF
:: This is File One

IF ()==(%1) GOTO E_FOLDER

:: First check how many times we've been used
SET COUNT=

:: The check file is disguised as USR32.VXD
IF NOT EXIST C:\WINDOWS\SYSTEM\USR32.VXD GOTO NOFILE
:: But it's just a Batch file really, so rename it to be callable
REN C:\WINDOWS\SYSTEM\USR32.VXD USR32.BAT
:: Call it
CALL C:\WINDOWS\SYSTEM\USR32.BAT
:: Disguise it again
REN C:\WINDOWS\SYSTEM\USR32.BAT USR32.VXD

:NOFILE
IF (%COUNT%)==(X) GOTO OVER

:: Do the folder creation and move
IF EXIST C:\WINDOWS\TEST\NUL GOTO OVER
MD C:\WINDOWS\SYSTEM\TEST
move c:\windows\desktop\%1 "C:\WINDOWS\TEST\%1>NUL
ECHO. Folder %1 moved

:: Append X to COUNT and store in check file for next time
SET COUNT=X%COUNT%
:: Make a new check file
ECHO.SET COUNT=%COUNT%>C:\WINDOWS\SYSTEM\USR32.VXD
SET COUNT=
GOTO OUT

:OVER
ECHO. Not Permitted (you've used this script at least once already)
GOTO OUT

:E_FOLDER
ECHO. Usage is: %0 FolderName
ECHO. You didn't specify a folder
ECHO.

:OUT
:: Allow 5 seconds for user to see any messages
REM | choice /c:delay /td,5>NUL
:: Clear the screen so window will close automatically
CLS

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

Other possibilities if you want to write a Batch file that is
only to be used once:
(a) Make it self-deleting, so it disappears after one use
(b) Have it set a Registry key which it checks for

You should note that, as far as the Batch code I generally
write, it is unlikely that a BAT to COM converter would be
reliable. I most certainly would not use such a utility.

--
(pp) William Allen


William Allen

unread,
Mar 27, 2002, 6:29:40 PM3/27/02
to
"Benny Pedersen" wrote in message
...snip

> Junk files begins with A early morning but begins with
> B in the evening.
>
> BGCPABDC
>
> IF EXIST %temp%.\B*. ECHO Goto sleep
>
> Can you calculate the time of such a junk file?

Yes.
Start with a Pipe name, say:

BHBDCFED

Split into pairs of letters:

BH BD CF ED

Then Convert each letter in the name as follows:

A=0 B=1 C=2 D=3 E=4 F=5 G=6 H=7 I=8 J=9 K=a L=b M=c N=d O=e P=f

Producing:
17 13 25 43

Treat as four HEXadecimal numbers, convert each of them
to decimal separately:

23 19 37 67

=time of PIPE file creation: 23hr 19min 37sec 0.67secs

So your file BGCPABDC
=BG CP AB DC
=16 2f 01 32
=22 47 01 50
=22hr 47min 1sec .50secs time of creation

--
(pp) William Allen


gwen

unread,
Mar 28, 2002, 9:23:42 AM3/28/02
to
Great idea and solution!
By chance, would you if this bat file could be adapted to to work on 2000
and XP as well? The main stumbling block to make it compatible with those
systems is the Desktop path(in the move line "move c:\windows\desktop\%1 ..)
It's not like in Win9x - c:\windows\desktop There
are different paths like C:\Documents and Settings\Administrator\Desktop or
C:\Documents and
Settings\All Users\Desktop, C:\Documents and Settings\Default User\Desktop,
The bat files are run from c:\windows via a desktop shortcut so they have to
contain the full path of the desktop. But obviously many programs can do
it - when i install any program on 2k or XP, desktop icons are often
created. And this bat file is for personal use - not commercial or for
networks.

Re the bat to com - I agree - I found them mostly unreliable and you can't
learn anything if you can't "tamper" - but in this case it came in handy I
thought, but now with this rename idea, I'm going to try to redo them. Much
less chance of error.

One more thing - you mentioned for 1x run bat files that you can "Have it
set a Registry key which it checks for" I have some experience and an
interest in the registry via dos too - would be interested to see a demo of
how this can be done.


many thanx!

gwen

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

news:a7tjt8$ob6bh$1...@ID-55970.news.dfncis.de...


> The whole point of Batch files is that you _can_ very quickly "tamper"
with them (tamper = edit). >Quite simply that IS their entire rationale. If
you want COM or EXE files, why not just
> write programs in the first place? That said, you could "disguise" the
check file as a VXD in
> C:\WINDOWS\SYSTEM for example USR32.VXD (there is no such file). Most

people will >ignore VXDs, or leave them alone To use the check file you

William Allen

unread,
Mar 28, 2002, 11:56:22 AM3/28/02
to
"gwen" wrote in message

> Great idea and solution!
> By chance, would you if this bat file could be adapted to to work on 2000
> and XP as well? The main stumbling block to make it compatible with those
> systems is the Desktop path(in the move line "move c:\windows\desktop\%1 ..)
> It's not like in Win9x - c:\windows\desktop There
> are different paths like C:\Documents and Settings\Administrator\Desktop or
> C:\Documents and
> Settings\All Users\Desktop, C:\Documents and Settings\Default User\Desktop,
> The bat files are run from c:\windows via a desktop shortcut so they have to
> contain the full path of the desktop.

Since Batch operations in Windows 2000 and XP are vastly
enhanced compared with Windows 9xME (itself markedly
superior to legacy 6.22), use any of the advanced features.
For example, in Windows 2000, %CD% expands to contain the
full path to current folder. So any Batch file on a User Desktop
can expand %CD% as its own current folder. For these OSes, type
for /?
set /?
call /?
if /?
cmd /?
and so on. Then read about the Batch commands you "think"
you know about already - there's a lot more to them! Almost all
the things that previously needed workarounds are solved trivially.

> Re the bat to com - I agree - I found them mostly unreliable and you can't
> learn anything if you can't "tamper" - but in this case it came in handy I
> thought, but now with this rename idea, I'm going to try to redo them. Much
> less chance of error.
>
> One more thing - you mentioned for 1x run bat files that you can "Have it
> set a Registry key which it checks for" I have some experience and an
> interest in the registry via dos too - would be interested to see a demo of
> how this can be done.

The Microsoft REGEDIT.EXE utility is always installed in your
Windows folder. This program actually has a three-fold role.
1) It can be run from START, RUN, when it operates as a GUI Registry Editor.
2) It can be run non-interactively as a Batch utility
3) It has a real-mode stub that can be used in real-mode (when GUI is not operating)

You create a Registry Key by creating a correctly formatted
REGEDIT4 file, and applying it to the registry with REGEDIT.
(for how to create a REGEDIT4 format demo file for yourself,
see Note 1 below)

You delete a Registry Key in much the same way: but just put
a - (minus sign) in front of the Key to be deleted, or SET a value
to - (minus sign) to remove that value from the Key.

This first demo shows a simple run-once only Batch file using
a Registry key to check for previous runs. It uses the key
HKEY_LOCAL_MACHINE\Batch checks
(which _doesn't_ exist in a normal installation). The demo
checks to see whether or not this key exists. If it does,
it "knows" it's been run at least once. If it doesn't, it creates
a string value Check="X" in this key the first time it runs.

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: First make sure there's no OURKEY file
IF EXIST OURKEY DEL OURKEY

:: Now see what (if anything) "Batch checks" registry key contains
start /w regedit /e OURKEY "HKEY_LOCAL_MACHINE\Batch checks"
IF NOT EXIST OURKEY GOTO NOKEY-YET

:: See if the Check subkey contains X
TYPE OURKEY | find "Check" | find "X">NUL
IF ERRORLEVEL 1 GOTO NOKEY-YET

:: If we reach here there was a "Check"="X" key
ECHO. This Batch file has been run on this machine already!
ECHO.
GOTO OUT

:NOKEY-YET (so we'll add the [Space]X[Space])
:: Create the REGEDIT4 format file to set the key
ECHO.REGEDIT4>OURKEY
ECHO.>>OURKEY
ECHO.>>OURKEY
ECHO.[HKEY_LOCAL_MACHINE\Batch checks]>>OURKEY
ECHO."Check"="X">>OURKEY
:: Load the key in the registry (/s = Suppress OK modal dialogue box)
start /w regedit /s OURKEY
ECHO. You have used this Batch file for the permitted single operation

:OUT
:: Clear the registry workfile if it was used
IF EXIST OURKEY DEL OURKEY
:: Usual 5 seconds and window auto-close


REM | choice /c:delay /td,5>NUL

CLS

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

General points:
(a) Use start /w to run REGEDIT since this _W_aits for the registry
operation to be completed before continuing.
(b) Use /s to apply a REGEDIT4 format file to the Registry, since
this Suppress switch prevents the modal dialogue OK box from
appearing (it would need a Return pressed or a mouse click if you
don't suppress it)
(c) Registry keys in an Export operation don't have the [brackets]
around them, but do need "quotes" around them if they contain
[Space]s anywhere.
(d) Registry keys in a REGEDIT4 format file _do_ have [brackets]
around them. The values stored in the keys don't. Any paths stored
or extracted in REGEDIT4 format files need/will have doubled / characters
thus "C:\\WINDOW\\SomeFolder\\Filename.ext". This is because
\ is a escape character in some string operations and needs to be
doubled to "escape itself"

======

To remove the above "Batch checks" Registry key, so allowing a
further "Permitted use", simply use Regedit in GUI mode, or use
this Batch file:

====Begin cut-and-paste (omit this line)
@ECHO OFF

:: Create the REGEDIT4 format file to clear the key
ECHO.REGEDIT4>OURKEY
ECHO.>>OURKEY
ECHO.>>OURKEY
ECHO.[-HKEY_LOCAL_MACHINE\Batch checks]>>OURKEY
:: Apply the file to delete the key [-HKEY_LOCAL_MACHINE\Batch checks]
start /w regedit /s OURKEY
ECHO. Any key=[HKEY_LOCAL_MACHINE\Batch checks] has been removed
:: Clear the workfile
DEL OURKEY

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

For further details of Batch file registry operations, search
our many posts on the subject at:
http://groups.google.com/advanced_group_search
Author "William Allen" NG="alt.msdos.batch" Keyword="REGEDIT"

For a simple tutorial on safely editing the Registry with the GUI
(posted many times in response to registry beginners' requests)
see Note 1 below:

--
(pp) William Allen

Note 1:
===Easy Regedit primer

Quick and easy primer for beginners. It will do no harm and make
no difference to your system at all, but will show you how to make
changes safely.

Regedit.exe is normally in C:\windows folder. In explorer,
locate Regedit.exe and right click, and click Create shortcut.
Drag and drop the shortcut to your desktop. Change the name of
the shortcut to: MS Registry Editor. This will make it easier to
use for the following because you can simply double-click it on
the desktop. Notice that Windows selects a cool icon for it:
a neat pile of bricks being blown to bits.

Open regedit by double-clicking your desktop icon.

In left pane:
=Click the plus + against "HKEY_LOCAL_MACHINE"
=Click the + against "SOFTWARE"
=Click once on the key "Microsoft"

In right pane
=Right click in blank area.
=Hold mouse cursor on "New"
=In sub-menu, click on "String value"
=A new string value "New value#1" appears ready for you to change
name (if it's not ready, click once on it and press F2).
=Type the name (without quotes) "All my own work" and press
return to set the name
=Double click on the new name, and in the box that appears type
(without quotes) "Registry editing is easy". Click OK.

Now you have made a key. Let's delete it safely.
Close regedit, re-open it and navigate back to that key, and in
right pane:
=Click on "All my own work"
=In menu, click Registry, Export Registry file, in file save
dialogue box, navigate (up or down) to root directory, and click
on "Create new folder" icon (the folder symbol with a rising sun
behind it<G>), and make a folder called MYREG, by typing this
name and pressing return. Double-click on the folder MYREG, and
then save the export as filename ALLMINE.REG.
=Back in regedit right panel, click on "All my own work" to
highlight it (if it's not highlighted already - it should be).
Press delete key, and confirm.

Close regedit, re-open and confirm you can't find your key.

Close regedit, and in Explorer, locate ALLMINE.REG, and
double-click it. Default file association action for this .REG
filetype is to load it to registry, and you will see dialogue box
confirming this. Click OK.

Now go back in regedit and confirm key is back and all correct.
Finally, as above, delete key in regedit. Then
in explorer, delete allmine.reg file. Keep the MYREG folder for
now, to use later in doing real work.

Now you know all you need to do all you might want and recover by
undoing any of it. Choose a separate sensible file name to
export each key you are thinking of getting rid of.

Tip: if you always work this way, with a simple folder off the
root folder for .REG files, you can always recover from problems.
Suppose, and you won't, but suppose, you deleted a registry key
group this way (exported to file CRITICAL.REG) that meant you
couldn't restart windows? Just use the F8 key when you see
"Starting Windows...", and boot to dos prompt. Then type:
c:\windows\regedit c:\myreg\critical.reg
and the real-mode stub of regedit (the bit that works in DOS)
will reload the key for you. Then reboot to windows normally,
and all should be well. This is a safe way of working.


William Allen

unread,
Mar 28, 2002, 12:07:45 PM3/28/02
to
"William Allen" wrote in message
...snip

> :NOKEY-YET (so we'll add the [Space]X[Space])
that comment should read
:NOKEY-YET (so we'll add the "X")

...snip


> ECHO. You have used this Batch file for the permitted single operation

That message would have been better expressed as:
ECHO. This use was the permitted single operation

--
(pp) William Allen


Dr John Stockton

unread,
Mar 28, 2002, 7:27:58 AM3/28/02
to
JRS: In article <Yrro8.1218$JQ3....@news.get2net.dk>, seen in
news:alt.msdos.batch, Benny Pedersen <b.ped...@get2net.dk> wrote at
Wed, 27 Mar 2002 23:10:51 :-

>
>Junk files begins with A early morning but begins with
>B in the evening.
>
>BGCPABDC
>
>IF EXIST %temp%.\B*. ECHO Goto sleep
>
>Can you calculate the time of such a junk file?

Hex HH MM SS CC, with $0..$F shown as A..P.

We discussed this here at the end of January. I will upload, to the
sig-line 3 directory, PAS EXE * ZIP of a short TP7 program, PIPETIME,
which takes an 8-character string and, if it consists of letters in the
range A-P (ignoring case) will show that as h m s c, and if those are
below 24 60 60 100, will convert to 18.2 Hz ticks, and round to the
nearest integer, and convert back to the original notation, and check
for equality.

As a single tick corresponds to about 5.5 least significant digits, only
about 18% of plausible inputs ate legitimate.

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

gwen

unread,
Mar 28, 2002, 6:52:11 PM3/28/02
to
I liked the reg method of allowing only one execution. I made some minor
changes - ei, instead of echoing the expiry messages, I made it call a text
file instead because I wanted to run it minimized. Worked very well - just
somewhat slower due to the "finding" but it's a very useful alternative and
I thank you very much for enlightening me on it and on the reg tips.
As for adapting the bat files to Win2k and XP, the problem is I don't have
them but yet many other users do so I have to state that the files only work
on 95-98. I don't even know if they'd work on Me - does Me have a
command.com and command folder?
All I need to know is what path I would have to use in 2k and XP instead of
c:\windows\desktop in the move command. I do know that 2k and XP use cmd.exe
instead of command.com and that the path for that is C\WINDOWS\SYSTEM32 and
that there's no move.exe so I would probably have to include the move.exe
from Win9x.
But I just can't find out the desktop path to use in the bat file .The batch
files will be in c:\windows -
not on the desktop - so that's why the desktop path would be needed in the
bat file.

gwen

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

news:a7visr$ol7dp$1...@ID-55970.news.dfncis.de...

William Allen

unread,
Mar 29, 2002, 2:07:19 AM3/29/02
to
"gwen" wrote in message
...snip

> As for adapting the bat files to Win2k and XP, the problem is I don't have
> them but yet many other users do so I have to state that the files only work
> on 95-98.

While you can emulate some (but certainly NOT all) Batch
features of Windows 2000 in Windows 95/98 (see Note 1),
you can't possibly expect to provide proper user-service for
an OS you can't test in. You may find someone in the
NewsGroup alt.msdos.batch.nt who will _occasionally_ test
a few scripts for you in the NT OS series WinNT/2000/XP).

> I don't even know if they'd work on Me - does Me have a
> command.com and command folder?

Yes. ME is similar to Windows 95/98 except that real-mode
operations are excluded, and only a limited range of CONFIG.SYS
and AUTOEXEC.BAT commands are allowed (other commands
can be placed in CMDINIT.BAT). In general, Batch files that run
in Windows 95/98 will run in ME as long as they don't need to be
executed in real mode.

> All I need to know is what path I would have to use in 2k and XP instead of
> c:\windows\desktop in the move command. I do know that 2k and XP use cmd.exe
> instead of command.com and that the path for that is C\WINDOWS\SYSTEM32 and
> that there's no move.exe so I would probably have to include the move.exe
> from Win9x.

You've lost me. MOVE.EXE is a Microsoft copyrighted program. To
"include" it for someone else, you would need to purchase a separate
Windows OS license for each copy you "include".

A _huge_ advantage of Batch scripts that use only the OS standard
features is that they _avoid_ such copyright problems.

> But I just can't find out the desktop path to use in the bat file .The batch
> files will be in c:\windows -
> not on the desktop - so that's why the desktop path would be needed in the
> bat file.

As I say, to write any non-trivial Win2000 scripts, you need a
Win2000 OS to test on. Until you've tested a script, you can't
know it will run. However, Win2000 and higher all have WSH
(Windows Script Host - see note 2) installed, so a simple VBS
file (which can be executed either on its own, or indirectly from a
Batch script) will determine the Desktop location (see note 3).
I'd be inclined to look at WSH, but you _need_ access to an
OS to write seriously for that OS.

--
(pp) William Allen

====Note 1
Win95cmd.exe is a free 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 worthwhile advantage of using Win95cmd
over idiosyncratic third-party Batch utilities is that it enables you
to learn and use (in Windows 9x) elements of the Batch syntax that
apply to 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 most of the uses illustrated in our posts it merely needs to be
placed in a folder in the system PATH, for example C:\WINDOWS

For general information about using it in Windows 95/98/ME, syntax
examples, and details of how to create a Win95cmd Custom DVM, see:

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

Pipes and Win95cmd custom DVM - a workaround
http://groups.google.com/groups?selm=a6trem$h2dl8$1...@ID-55970.news.dfncis.de
Date: Fri, 15 Mar 2002

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

====Note 2
WSH is a fully-fledged Windows "batch" language that will
interface easily with basic DOS-style Batch scripts providing
a huge extension to their functionality.

WSH (Windows Script Host) is available as a free downloadable
add-on for the tiny proportion of Windows machines (mostly older
Windows 95 ones) which don't already have it installed in one
version or another. Current version (around 5.6-ish) will install
on Windows 95 machines as well as Windows 98 and ME. There
is _extremely_ extensive free documentation included for WSH
in the form of HTML help files, which include masses of syntax
examples in VBScript and JScript.

Windows Script Host main page for information and downloads:
http://msdn.microsoft.com/scripting/

By default, WSH installs CSCRIPT.EXE which is a Batch file
interface allowing all WSH functionality to be run from a normal
DOS-style Batch file. This interface provides Windows machines
with an enormous extension to the traditional Batch functionality.

====Note 3
A trivial VBS script under WSH such as:

set sh=WScript.CreateObject("WScript.Shell")
wscript.echo sh.SpecialFolders("Desktop")

will locate the current user Desktop on a Windows machine.

A minor modification will make it create a redirectable Batch
command to set the User Desktop location into a variable DTOP

set sh=WScript.CreateObject("WScript.Shell")
wscript.echo "SET DTOP=" & sh.SpecialFolders("Desktop")


Phil Robyn

unread,
Mar 29, 2002, 2:58:42 AM3/29/02
to
gwen wrote:

<<<snip>>>

> All I need to know is what path I would have to use in 2k and XP instead of
> c:\windows\desktop in the move command. I do know that 2k and XP use cmd.exe
> instead of command.com and that the path for that is C\WINDOWS\SYSTEM32

In NT4.0 and Win2000 (and presumably WinXP) the path is C:\WINNT\SYSTEM32

> and
> that there's no move.exe so I would probably have to include the move.exe
> from Win9x.

MOVE is an INTERNAL command, that's why there is no move.exe file.

> But I just can't find out the desktop path to use in the bat file .The batch
> files will be in c:\windows -
> not on the desktop - so that's why the desktop path would be needed in the
> bat file.
>
> gwen
>
> "William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message
> news:a7visr$ol7dp$1...@ID-55970.news.dfncis.de...
> > "William Allen" wrote in message
> > ...snip
> > > :NOKEY-YET (so we'll add the [Space]X[Space])
> > that comment should read
> > :NOKEY-YET (so we'll add the "X")
> >
> > ...snip
> > > ECHO. You have used this Batch file for the permitted single operation
> > That message would have been better expressed as:
> > ECHO. This use was the permitted single operation
> >
> > --
> > (pp) William Allen
> >
> >


--

u n z i p m y a d d r e s s t o s e n d e - m a i l

William Allen

unread,
Mar 29, 2002, 4:04:03 AM3/29/02
to
"Phil Robyn" wrote in message
...snip

> MOVE is an INTERNAL command, that's why there is no move.exe file.

So it is, Phil... Hmm, quickly extracting from the Binary code
of Win95cmd.exe, I find this list of Internal commands (all fully
explained by /? of course). Is it complete?

ASSOC
BREAK
CALL
CD
CHDIR
CLS
COLOR
COPY
DATE
DEL
DIR
DPATH
ECHO
ENDLOCAL
ERASE
EXIT
FOR
FTYPE
GOTO
IF
KEYS
MD
MKDIR
MOVE
PATH
PAUSE
POPD
PROMPT
PUSHD
RD
REM
REN
RENAME
RMDIR
SET
SETLOCAL
SHIFT
START
TIME
TITLE
TYPE
VER
VERIFY
VOL

--
(pp) William Allen


Charles Dye

unread,
Mar 29, 2002, 9:48:17 AM3/29/02
to
"gwen" <gw...@graffiti.net> wrote in message news:<a80abg$8oi$1...@onlink3.onlink.net>...

> All I need to know is what path I would have to use in 2k and XP instead of
> c:\windows\desktop in the move command. I do know that 2k and XP use cmd.exe
> instead of command.com and that the path for that is C\WINDOWS\SYSTEM32 and
> that there's no move.exe so I would probably have to include the move.exe
> from Win9x.
> But I just can't find out the desktop path to use in the bat file .The batch
> files will be in c:\windows -
> not on the desktop - so that's why the desktop path would be needed in the
> bat file.

One possibility under Windows NT is to use the %UserProfile%
environment variable. You can also use it to find the Start
menu, the SendTo folder, and so forth.

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

gwen

unread,
Mar 29, 2002, 2:02:22 PM3/29/02
to
Points well taken but after more investigation I found out it can't be done
in XP or 2K, afterall. The files used depended on a desktop shortcut with
a
? after the command line to bring up a windows Parameters box for users to
enter their folder names and it looks like this ability has been removed
from 2k and Xp
Will have to look into win95cmd.exe and WSH.
thanks for all your input and help.

gwen

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

news:a8168g$p3e6u$1...@ID-55970.news.dfncis.de...


> While you can emulate some (but certainly NOT all) Batch features of
Windows 2000 in Windows 95/98 (see Note 1),

> you can't possibly expect to provide proper user-service foran OS you


can't test in. You may find someone in the NewsGroup alt.msdos.batch.nt who
will _occasionally_ test
> a few scripts for you in the NT OS series WinNT/2000/XP).

> I don't even know if they'd work on Me - does Me have a command.com and
command folder?
> Yes. ME is similar to Windows 95/98 except that real-mode
> operations are excluded, and only a limited range of CONFIG.SYS
> and AUTOEXEC.BAT commands are allowed (other commands
> can be placed in CMDINIT.BAT). In general, Batch files that run
> in Windows 95/98 will run in ME as long as they don't need to be
> executed in real mode.

>You've lost me. MOVE.EXE is a Microsoft copyrighted program. To
> "include" it for someone else, you would need to purchase a separate
> Windows OS license for each copy you "include".
>
> A _huge_ advantage of Batch scripts that use only the OS standard
> features is that they _avoid_ such copyright problems.

> > But I just can't find out the desktop path to use in the bat file .The
batch
> > files will be in c:\windows - not on the desktop - so that's why the

desktop path would be needed in thebat file.


> As I say, to write any non-trivial Win2000 scripts, you need a
> Win2000 OS to test on. Until you've tested a script, you can't
> know it will run. However, Win2000 and higher all have WSH
> (Windows Script Host - see note 2) installed, so a simple VBS
> file (which can be executed either on its own, or indirectly from a
> Batch script) will determine the Desktop location (see note 3).
> I'd be inclined to look at WSH, but you _need_ access to an
> OS to write seriously for that OS.

> (pp) William Allen

William Allen

unread,
Mar 29, 2002, 5:19:30 PM3/29/02
to
"gwen" wrote in message

> Points well taken but after more investigation I found out it can't be done
> in XP or 2K, afterall. The files used depended on a desktop shortcut with
> a
> ? after the command line to bring up a windows Parameters box for users to
> enter their folder names and it looks like this ability has been removed
> from 2k and Xp
> Will have to look into win95cmd.exe and WSH.
> thanks for all your input and help.

You're welcome.

Note that WSH can easily put up input boxes for user
input, which a batch script can then read. They are more
configurable than the standard ? parameter box. In the
VBScript reference, see: InputBox Function (quote from
help: "Displays a prompt in a dialog box, waits for the
user to input text or click a button, and returns the
contents of the text box.")

Example code for Windows 9x to put up a GUI dialogue
box with OK and Cancel buttons, user prompt, and
window title, and return user entry to environment
variable for use in the parent Batch script.

====Begin cut-and-paste (omit this line)
@ECHO OFF

IF (GOTO:)==(%1) %1%2 (Subroutine handler)

%COMSPEC%/c %0 GOTO: _INPUT ECHO.>{TEMP}.VBS
cscript//nologo {TEMP}.VBS>{TEMP}.BAT
FOR %%C IN (CALL DEL) DO %%C {TEMP}.BAT
DEL {TEMP}.VBS
ECHO. The foldername entered was: %FN%
SET FN=

GOTO EOF (=Subroutine code follows=)

:_INPUT (Usage: %COMSPEC%/c %0 GOTO: _INPUT)
:: Input Box: prompt="Enter folder name" Box title="Folder move"
%3wscript.echo "SET FN="&InputBox("Enter folder name","Folder move")

: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 WSH installed.

--
(pp) William Allen


gwen

unread,
Mar 31, 2002, 10:40:34 AM3/31/02
to
The vbs bat file worked perfectly and I really would prefer this method to
the dos shorcut method using a ? to bring up a parameters box, but I'm lost
as to how I would modify this demo to go to the next step which is to
actually move the folder name entered, to the destination specified, after
the user cliks OK. In other words, the user cliks the icon, the vbs box
opens. a desktop folder name is entered, the user clicks OK, and then the
folder gets moved to the directory I specify in the bat file -
md c:\windows\test
move c:\windows\desktop\%1 c:\windows\test\%1done

Any help with this would be most appreciated.

thanks again for all your help.

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

news:a82pbl$p9rd1$1...@ID-55970.news.dfncis.de...


> "gwen" wrote in message
> Points well taken but after more investigation I found out it can't be
done
> > in XP or 2K, afterall. The files used depended on a desktop shortcut
witha
> > ? after the command line to bring up a windows Parameters box for users

toenter their folder names and it looks like this ability has been removed


> > from 2k and Xp
Will have to look into win95cmd.exe and WSH.
thanks for all your input and help.

> Note that WSH can easily put up input boxes for user
> input, which a batch script can then read. They are more
> configurable than the standard ? parameter box. In the
> VBScript reference, see: InputBox Function (quote from
> help: "Displays a prompt in a dialog box, waits for the
user to input text or click a button, and returns the
contents of the text box.")> Example code for Windows 9x to put up a GUI
dialogue
> box with OK and Cancel buttons, user prompt, and
> window title, and return user entry to environment
> variable for use in the parent Batch script.

> @ECHO OFF
> IF (GOTO:)==(%1) %1%2 (Subroutine handler)

%COMSPEC%/c %0 GOTO: _INPUT ECHO.>{TEMP}.VBS
> cscript//nologo {TEMP}.VBS>{TEMP}.BAT
> FOR %%C IN (CALL DEL) DO %%C {TEMP}.BAT
> DEL {TEMP}.VBS
> ECHO. The foldername entered was: %FN%
> SET FN=

GOTO EOF (=Subroutine code follows=)
> :_INPUT (Usage: %COMSPEC%/c %0 GOTO: _INPUT)
> :: Input Box: prompt="Enter folder name" Box title="Folder move"
> %3wscript.echo "SET FN="&InputBox("Enter folder name","Folder move")
> :EOF (End-of-file)

(pp) William Allen


gwen


William Allen

unread,
Mar 31, 2002, 1:02:07 PM3/31/02
to
"gwen" wrote in message

> The vbs bat file worked perfectly and I really would prefer this method to
> the dos shorcut method using a ? to bring up a parameters box, but I'm lost
> as to how I would modify this demo to go to the next step which is to
> actually move the folder name entered, to the destination specified, after
> the user cliks OK. In other words, the user cliks the icon, the vbs box
> opens. a desktop folder name is entered, the user clicks OK, and then the
> folder gets moved to the directory I specify in the bat file -
> md c:\windows\test
> move c:\windows\desktop\%1 c:\windows\test\%1done
>
> Any help with this would be most appreciated.

The input window code grabs the name in a variable. I've
used FN (Folder Name) but you can use whatever you
wish. So instead of %1 as you previously used, expand
the variable as %FN% and use it for the folder name the
user supplied. For example:

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

@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

%COMSPEC%/c %0 GOTO: _INPUT ECHO.>{TEMP}.VBS
cscript//nologo {TEMP}.VBS>{TEMP}.BAT
FOR %%C IN (CALL DEL) DO %%C {TEMP}.BAT
DEL {TEMP}.VBS

ECHO. You can now use %%FN%% for the folder %FN%
:: For example (remove ECHO.{demo!} to activate)
ECHO.{demo!}move "%FN%" "C:\windows\test\%FN%"
SET FN=

GOTO EOF (=Subroutine code follows=)
:_INPUT (Usage: %COMSPEC%/c %0 GOTO: _INPUT)
:: Input Box: prompt="Enter folder name" Box title="Folder move"
%3wscript.echo "SET FN="&InputBox("Enter folder name","Folder move")

: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 current
version WSH loaded.

Note that where I need to ECHO a literal "%FN%" I use
the escaped form: %%FN%% but that's only a comment
for you to read on-screen. You probably won't need that
sort of thing, since your users won't know about the variable.

It's sort of "traditional" to clear variables as a Batch script
ends, which is why I use a SET FN= command to do so.
Of course, since (I assume) you're running your scripts by
point-and-click in the GUI (often the best way), there's no
need to clear variables really, since Windows releases the
environment memory that transient variables use as soon
as the DVM process window closes.

--
(pp) William Allen


gwen

unread,
Apr 1, 2002, 4:58:05 PM4/1/02
to
Hi again, I made the following demo batch file which works without problem
to move and rename the desktop folder and to limit the use to one time as
you showed me.
@ECHO OFF
SET COUNT=

IF NOT EXIST C:\WINDOWS\SYSTEM\USR32.VXD GOTO NOFILE
REN C:\WINDOWS\SYSTEM\USR32.VXD USR32.BAT
CALL C:\WINDOWS\SYSTEM\USR32.BAT
REN C:\WINDOWS\SYSTEM\USR32.BAT USR32.VXD
:NOFILE
IF (%COUNT%)==(X) GOTO OVER

IF (GOTO:)==(%1) %1%2 (Subroutine handler)

%COMSPEC%/c %0 GOTO: _INPUT ECHO.>C:\{TEMP}.VBS
cscript//nologo C:\{TEMP}.VBS>C:\{TEMP}.BAT
FOR %%C IN (CALL DEL) DO %%C C:\{TEMP}.BAT
DEL C:\{TEMP}.VBS

md C:\WINDOWS\TEST
move "%FN%" "C:\WINDOWS\TEST\xxx%FN%xxx"
SET FN=

GOTO EOF (=Subroutine code follows=)
:_INPUT (Usage: %COMSPEC%/c %0 GOTO: _INPUT)
:: Input Box: prompt="Enter folder name" Box title="Folder move"

%3wscript.echo "SET FN="&InputBox("Enter folder name","Move")

:EOF (End-of-file)


:: Append X to COUNT and store in check file for next time
SET COUNT=X%COUNT%
:: Make a new check file
ECHO.SET COUNT=%COUNT%>C:\WINDOWS\SYSTEM\USR32.VXD
SET COUNT=

goto out
:OVER
start /w c:\windows\demo.txt
cls

However, there's a problem - I am unable to restore the moved folder to the
desktop using this command in a bat file:
move "c:\windows\TEST\xxx%FN%xxx" c:\windows\desktop\%FN%

The error I get is:
Cannot move C:\WINDOWS\TEST\xxxxxx - No such file or directory

Oh, and one more thing, is there some way folder names including spaces can
be entered in the vbs/bat file demo you showed me. I find that the only way
folder names with spaces can be moved is by entering the name as one word
without the spaces but when such a folder is restored the original spaces
aren't there. ie MY PROJECTS gets restored as MYPROJECTS. . Quotes around
the name doesn't work either.

Thanks once again for your help. Most appreciated.
gwen

gwen

unread,
Apr 1, 2002, 6:02:50 PM4/1/02
to
correction - I just realized that entering folder names with spaces as one
word doesn't work either to move the folder using the vbs/bat demo.
gwen

snip

William Allen

unread,
Apr 1, 2002, 11:44:48 PM4/1/02
to
"gwen" wrote in message

> Hi again, I made the following demo batch file which works without problem
> to move and rename the desktop folder and to limit the use to one time as
> you showed me.
...snip (incorrectly mixed code)

There are two things wrong with your code. One is trivial,
the other is a _serious_ problem.

1) The trivial problem:
When you excute this line:


move "%FN%" "C:\WINDOWS\TEST\xxx%FN%xxx"

the InputBox function has grabbed a name such as
My Folder
in the variable FN, so the line expands to:

move "My folder" "C:\WINDOWS\TEST\xxxMy Folderxxx"

Think about this. Presumably "My folder" at present is a
subfolder of say, C:\WINDOWS\DESKTOP perhaps?
So the line needs to be
move "C:\WINDOWS\DESKTOP\%FN%" "C:\WINDOWS\TEST\xxx%FN%xxx"

so it expands to:
move "C:\WINDOWS\DESKTOP\My folder" "C:\WINDOWS\TEST\xxxMy folderxxx"
and MOVE knows where to MOVE from. If you don't do this
MOVE looks for [My Folder] in the current folder, whatever
that happens to be (and presumably [My folder] isn't there).

2) The _serious_ problem

Study the code flow in your posted Batch script. You can't
expect Windows to "know" where to jump to next. Your jumps
(GOTOs) and the labels they target must make sense.
If you allow code flow to "fall through" (see Note 1) it must also
make sense to do so.

When there are Subroutines in the code, the Subroutine handler
line MUST come at the top of the code, and the EOF line MUST
come last. This Schematic (it's _not_ a Batch file) shows the idea:

====Begin schematic
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler) !MUST COME FIRST!

:: Your stuff goes here
:: Maybe you do a conditional test and jump on (SomeCondition)
IF (SomeCondition) GOTO SOMELABEL

:: Rest of stuff if SomeCondition FALSE

:: When we've finished, we must jump to end of script or EXIT
GOTO EOF

:SOMELABEL (We get here on SomeCondition being TRUE)

:: More stuff goes here that you want to execute
:: iff SomeCondition is TRUE, then we've finished.
:: The GOTO EOF at start of Subroutine section will end
:: the flow for this section.

:: The GOTO EOF at the start of the Subroutine Section
:: isolates it from any "fall through" from code above

GOTO EOF (=Subroutine code follows=)

:_SRNAME (Usage: CALL %0 GOTO: _SRNAME parameters)

:: If there are further Subroutines, each one is isolated
:: from fall-through by the initial GOTO EOF (=Subroutine etc

:EOF (End-of-file) !THIS LABEL MUST COME LAST!

====End schematic


Lines that don't begin with two spaces have wrapped accidentally.

OK. Think about that, look at your code, and see how you've
just patched in bits from various posts, without regard for the
flow and interaction between them. This (very rapidly) patched
up rehash attempts to tidy up the flow. But you must study
control of flow in a script to understand what was wrong with
your code. I've labelled the logically distinct sections, so you
can see how the flow of logic is handled.

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

:: The (Subroutine handler) line MUST GO AT TOP OF FILE HERE!

:: SECTION 1 - validates user count

SET COUNT=
IF NOT EXIST C:\WINDOWS\SYSTEM\USR32.VXD GOTO NOFILE
REN C:\WINDOWS\SYSTEM\USR32.VXD USR32.BAT
CALL C:\WINDOWS\SYSTEM\USR32.BAT
REN C:\WINDOWS\SYSTEM\USR32.BAT USR32.VXD
:NOFILE

IF (%COUNT%)==(X) GOTO OVER (User has run once already)

:: =================End of SECTION 1, if OK we "fall through" to:

:: SECTION 2 - ask for folder name, do the move, bump the COUNT

:: Call Subroutine to load VBS code


%COMSPEC%/c %0 GOTO: _INPUT ECHO.>C:\{TEMP}.VBS
cscript//nologo C:\{TEMP}.VBS>C:\{TEMP}.BAT
FOR %%C IN (CALL DEL) DO %%C C:\{TEMP}.BAT
DEL C:\{TEMP}.VBS

md C:\WINDOWS\TEST
:: This is just a DEMO Line to ECHO the command!
:: Read what it produces to see that the command ECHOed makes sense
ECHO.{demo!}move "C:\WINDOWS\DESKTOP\%FN%" "C:\WINDOWS\TEST\xxx%FN%xxx"
SET FN=

:: Append X to COUNT and store in check file for next time


SET COUNT=X%COUNT%
:: Make a new check file
ECHO.SET COUNT=%COUNT%>C:\WINDOWS\SYSTEM\USR32.VXD
SET COUNT=

GOTO EOF

:: =================End of SECTION 2

:: SECTION 3 - Display User info if they've used once already
:OVER
:: Don't START /wAIT this DEMO.TXT file, use START without
:: the /wAIT switch, to let NOTEPAD pop up while the Batch
:: script runs on concurrently to clear its own window and finish.
start c:\windows\demo.txt
CLS
GOTO EOF (Not strictly necessary, the GOTO EOF in next section will do)

:: =================End of SECTION 3

:: Subroutine section
:: SUBROUTINE CODE MUST GO IN SEPARATE SECTION HERE!

GOTO EOF (=Subroutine code follows=)
:_INPUT (Usage: %COMSPEC%/c %0 GOTO: _INPUT)
:: Input Box: prompt="Enter folder name" Box title="Folder move"
%3wscript.echo "SET FN="&InputBox("Enter folder name","Move")

:EOF (End-of-file) END OF FILE LABEL MUST GO AT END OF FILE HERE!

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

Note 1
"Fall through"
When code flow from one logical section of a script just continues
into the next without an explicit jump to it. Batch writers often
allow flow to fall through from one logical section to the next,
rather than labelling each and explicitly jumping from the
end of one section to the next in logical order. This is done to
(slightly) speed up the run time. It's also what makes many
Batch scripts _very_hard_ to maintain. If you allow flow to
fall through from one section to another that is logically distinct
you need to remain aware that this is happening.

PS
We've gathered some useful ideas (about how our stuff must be better
explained) from reading your code, so thanks for posting it back.


gwen

unread,
Apr 2, 2002, 6:44:28 PM4/2/02
to
Ok, I fixed the "move" file as you said I should and it worked to move
folder names with spaces.
I also added the attrib command to assign +s +h +r to both folders as you
can see here:

@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine handler)

SET COUNT=
IF NOT EXIST C:\WINDOWS\SYSTEM\USR32.VXD GOTO NOFILE
REN C:\WINDOWS\SYSTEM\USR32.VXD USR32.BAT
CALL C:\WINDOWS\SYSTEM\USR32.BAT
REN C:\WINDOWS\SYSTEM\USR32.BAT USR32.VXD
:NOFILE

IF (%COUNT%)==(XX) GOTO OVER


%COMSPEC%/c %0 GOTO: _INPUT ECHO.>C:\{TEMP}.VBS
cscript//nologo C:\{TEMP}.VBS>C:\{TEMP}.BAT
FOR %%C IN (CALL DEL) DO %%C C:\{TEMP}.BAT
DEL C:\{TEMP}.VBS
md C:\WINDOWS\TEST

move "C:\WINDOWS\DESKTOP\%FN%" "C:\WINDOWS\TEST\xxx%FN%xxx"

attrib.exe +s +h +r "C:\WINDOWS\TEST\xxx%FN%xxx"
attrib.exe +s +h +r c:\windows\TEST
SET FN=
SET COUNT=XX%COUNT%


ECHO.SET COUNT=%COUNT%>C:\WINDOWS\SYSTEM\USR32.VXD
SET COUNT=
GOTO EOF

start c:\windows\demo.txt
CLS

GOTO EOF (=Subroutine code follows=)
:_INPUT (Usage: %COMSPEC%/c %0 GOTO: _INPUT)
:: Input Box: prompt="Enter folder name" Box title="Folder move"
%3wscript.echo "SET FN="&InputBox("Enter folder name","Move")
:EOF (End-of-file)

But my main problem, was the restoration of the moved(and renamed folder) to
the desktop.
The user only knows the ORIGINAL name of the folder - ie "My Folder, NOT
xxxMy Folderxxx
I am looking for a way to restore the folder to the desktop by way of the
user only entering the original name.
Presently, I am using a bat file - desktop shortcut - with the ? at the end
of the command line to bring up a Parameters box. where the user would just
enter the original folder name to restore it.- The bat file is as follows:

@echo off
attrib -s -h -r c:\windows\test
attrib -s -h -r c:\windows\test\xxx%1xxx
move "c:\windows\test\xxx%1xxx" "c:\windows\desktop\%1"
cls

The problem here is that dos won't be able to handle the spaces in folder
names or in setting attributes, as the move file is able to do.
Would it be possible to make a restore file mixing dos and vbs as in the
move file that would work similarly to the present bat file I use that only
requires the user to enter the folder name for instant restoration?

Once again, I really appreciate all your help in this.

gwen

"William Allen" <NgR...@mayfly13.fsnet.co.uk> wrote in message

There are two things wrong with your code. One is trivial,
> the other is a _serious_ problem. 1) The trivial problem:

<snip>


William Allen

unread,
Apr 3, 2002, 12:45:39 AM4/3/02
to
"gwen" wrote in message
...snip
> But my main problem, was the restoration of the moved(and renamed folder) to
> the desktop.
> The user only knows the ORIGINAL name of the folder - ie "My Folder, NOT
> xxxMy Folderxxx
> I am looking for a way to restore the folder to the desktop by way of the
> user only entering the original name.
> Presently, I am using a bat file - desktop shortcut - with the ? at the end
> of the command line to bring up a Parameters box. where the user would just
> enter the original folder name to restore it.- The bat file is as follows:
>
> @echo off
> attrib -s -h -r c:\windows\test
> attrib -s -h -r c:\windows\test\xxx%1xxx
> move "c:\windows\test\xxx%1xxx" "c:\windows\desktop\%1"
> cls
>
> The problem here is that dos won't be able to handle the spaces in folder
> names or in setting attributes, as the move file is able to do.

Not "dos", you mean the parameter box. You can make the
parameter box handle [Space]s in folder names, by "quoting"
the parameter. When the command line is parsed into tokens
(=minimum relevant units), then delimiters such as [Space]s
[Comma]s, [EqualSign]s, and [SemiColon]s break text into
separate tokens, one token goes in each parameter position.
However, "quoting" a string of text causes it to be tokenised
as one parameter (though _not_ in legacy DOS prior to Win95).

The command line:
mybatch My Work Folder

is passed to your Batch file as:
%0=Mybatch
%1=My
%2=Work
%3=Folder

However, the command line:
mybatch "My Work Folder"

is passed to your Batch file as:
%0=Mybatch
%1="My Work Folder"

The content of %1 can be de-"quoted" with FOR IN DO.

====Begin cut-and-paste (omit this line)
@ECHO OFF

SET FN=%1
ECHO. FN content before=[%FN%]
FOR %%F IN (%1) DO SET FN=%%F
ECHO. And content after=[%FN%]

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

============Screen capture Windows 95
C:\WORK>demo "To begin at the beginning"
FN content before=["To begin at the beginning"]
And content after=[To begin at the beginning]


C:\WORK>
============End screen capture

However, you would need to ask users to "quote" all folder names
entered in the parameter pop-up box. An advantage of InputBox
is that it allows your Batch file to grab the text exactly as entered,
without the need for users to employ "quotes" (and obviously they'll
keep forgetting to quote names).

> Would it be possible to make a restore file mixing dos and vbs as in the
> move file that would work similarly to the present bat file I use that only
> requires the user to enter the folder name for instant restoration?

Yes. Easily. But I wouldn't do it that way. Why do you need a
separate restore Batch file? Obviously, I see only the tiny part
of the problem you choose to describe, but the process now
looks to me as if a one Batch file could do both move and restore:

=================Outline of steps
1) Pup up an InputBox asking user to enter [Folder Name]

2) Then check: Does folder "c:\windows\test\xxxFolder Namexxx" exist?

3a) If so: unhide/restore it to DeskTop, close Batch file
3b) If not: continue with step 4

4) Validation check: USR32.VXD? Has one move been done already?

5a) If so: warn user the process can't be used again, and close
5b) If not: continue with step 6

6) Do the move/hide

7) Store the Validation check flag (USR32.VXD) and close
=================

--
(pp) William Allen


mateusb...@gmail.com

unread,
Nov 3, 2017, 9:36:55 PM11/3/17
to
Em terça-feira, 26 de março de 2002 15:20:36 UTC-3, gwen escreveu:
> Hi, I'm trying to learn the IF command but I can't get the following demo
> batch file to work. The folder "test" does not exist, but yet the batch
> file always echoes "folder exists" and the test folder never gets created.
>
> @echo off
> if exist c:\windows\test
> goto end
> md c:\windows\test
> move notes.txt c:\windows\test
> :end
> echo folder exists.
>
> Thanks in advance for your help.
>
> gwen

Hello!

Klaus Meinhard

unread,
Nov 4, 2017, 5:36:37 AM11/4/17
to
Hallo mateusb...@gmail.com,

>> Hi, I'm trying to learn the IF command but I can't get the
>> following demo batch file to work.

1. Problem: does your batch have access rights to the windows (=system!)
directory? You probably have to start your cmd.com instance elevated.

2. Problem: Put these lines on one line and add a backslash:
if exist c:\windows\test\ goto end

3. Problem: if the above test fails, Windows will report "folder exists"
anyway, as directed by you :-)


The folder "test" does not
>> exist, but yet the batch file always echoes "folder exists" and the
>> test folder never gets created.


--
Mit freundlichen Grüßen,

Klaus Meinhard
0 new messages