Re: Batch file



You can use the "exit" command in a batch file if you
wish to terminate it before it reaches the end, e.g. like so:

@echo off
if not exist c:\SomeFile.txt exit /b

This is equivalent to writing:

@echo off
if not exist c:\SomeFile.txt goto :eof

However, if you use this syntax:

@echo off
if not exist c:\SomeFile.txt exit

then the batch file will terminat and the current Command
Prompt (if you use one) will be closed too. This may not
be what you had intended.

The %UserProfile% variable includes embedded spaces
after it gets resolved (usually to c:\documents and settings\UserName).
This is why the double quotes are required. You can easily confirm
this by typing the following lines at the Command Prompt:

echo. > test.txt
copy test.txt "%UserProfile%"
copy test.txt %UserProfile%

The third command will fail.


"Royce" <Royce@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E07B223E-E274-4F97-807A-2B86753298BA@xxxxxxxxxxxxxxxx
> i am aware of the quotes and when to use them. correct me if i wrong, you
use
> them when there are spaces in the path. "%Userprofile%\Desktop\test.txt"
> should work the same as %Userprofile%\Desktop\test.txt and the exit thing
is
> just something i have always done : ) i was unaware of the exit /b vs.
exit.
> learn something new everyday. so pegasus when would exit be needed?
>
>
> "Pegasus (MVP)" wrote:
>
> > I wasn't even aware of the "Title" command. Good one!
> > Your code contains a small error. All your redirections should read
> >
> > >> "%Userprofile%\Desktop\test.txt"
> >
> > i.e. with the surrounding double quotes (which I'm sure you're aware
of!).
> > Furthermore, the "exit" command is superfluous.
> >
> >
> > "Royce" <Royce@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> > news:43733E19-6F67-4F01-A3EA-7316AAB0C97A@xxxxxxxxxxxxxxxx
> > > Or this...
> > >
> > > @echo off
> > > title COPYING FILES...
> > > for /l %%i in (1,1,11) do echo.
> > > echo Please Wait While Files Are Being Copied...
> > > echo Started Copying Files On %date% At %time% >>
> > > %Userprofile%\Desktop\test.txt
> > > xcopy C:\test G:\backup /e /c /f /h /y >>
%Userprofile%\Desktop\test.txt
> > > echo Stopped Copying Files On %date% At %time% >>
> > > %Userprofile%\Desktop\test.txt
> > > exit
> > >
> > > "George Schneider" wrote:
> > >
> > > > I need some help on this one. I want to copy all files from my
C:\test
> > to
> > > > G:\Backup. In addition I want to create a text file that displays
the
> > date
> > > > and time started and date and time finished. I want to script using
a
> > batch
> > > > file.
> > > >
> >
> >
> >


.



Relevant Pages

  • Re: Persisting env vars in cmd windows
    ... The help text for the command you question goes like this: ... format by typing this: echo %date% ... If you don't then the batch file will fail. ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Shell Script to Remove Old Files
    ... Note it needs a TSM server: ... # Verify command line arguments ... echo "\nError: $STARTDIR does not exist.\n" ...
    (comp.unix.admin)
  • Re: Need Help with a DOS script (if possible)
    ... were meant to run the batch file with the "echo" command in place in the ... It never did but you removed the "echo" command regardless. ... echo Checking the target folder xxx%Target%yyy ...
    (microsoft.public.windowsxp.general)
  • Re: Perfmon and batch file
    ... > event viewer and run command file. ... > but no execute the cmd file or execute it but not execute the ... You are probably making some assumptions in your batch file ... @echo off ...
    (microsoft.public.windows.server.general)
  • Re: Persisting env vars in cmd windows
    ... sharp and robust batch file. ... I open several Command windows in succession. ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)