PDA

View Full Version : Re: Batch file help needed to execute to muliple directories


guard
December 11th 03, 09:20 PM
The .Mount/\Command ".Rem" is the most versatile and
compatible method of commenting shell scripts under
Windows NT/2K/XP/K3.

..Rem performs CONSISTENTLY across all platforms and
allows comments ANYWHERE THAT A COMMAND IS ACCEPTED,
including within complex multiline statements.

In addition, the .Mt/\Cmds ".ShowComments" and ".HideComments" allow the
commented lines to be optionally displayed when testing your code (they are
hidden by default).

For example:
*******
C:\GuardPost>ntlib /q :FNL REM_Demo.cmd

C:\GuardPost>type %_FNL%
01. @ECHO OFF
02. SETLOCAL ENABLEEXTENSIONS
03.
04. IF /I "%1"=="REM" GOTO:CASE1
05. IF /I "%1"=="::" GOTO:CASE2
06. IF /I "%1"==".Rem" GOTO:CASE3
07.
08. ECHO:REM_Demo [ REM ^| :: ^| .Rem ]
09. %.ExitEL1%
10.
11. :CASE1
12.
13. %.DashLine%
14. ECHO:[internal REM command]
15. %.DashLine%
16.
17. FOR %%A IN (1 2 3) DO (
18. (ECHO:[%%A] Before the remarked line)
19. (REM [%%A] ***EMBEDDED COMMENT***)
20. (ECHO:[%%A] After the remarked line)
21. )
22.
23. GOTO:FINISH
24.
25. :CASE2
26.
27. %.DashLine%
28. ECHO:[Commonly used :: technique]
29. %.DashLine%
30.
31. FOR %%A IN (1 2 3) DO (
32. (ECHO:[%%A] Before the remarked line)
33. (:: [%%A] ***EMBEDDED COMMENT***)
34. (ECHO:[%%A] After the remarked line)
35. )
36.
37. GOTO:FINISH
38.
39. :CASE3
40.
41. %.DashLine%
42. ECHO:[Mount/\Command .Rem]
43. %.DashLine%
44.
45. FOR %%A IN (1 2 3) DO (
46. (ECHO:[%%A] Before the remarked line)
47. (%.Rem% [%%A] ***EMBEDDED COMMENT***)
48. (ECHO:[%%A] After the remarked line)
49. )
50.
51. GOTO:FINISH
52.
53. :FINISH
54.
55. %.UnderLine%
56. %.dtEcho% End of Script [%~nx0]
57. %.ExitEL0%

C:\GuardPost>REM_Demo
REM_Demo [ REM | :: | .Rem ]

C:\GuardPost>REM_Demo REM
----------------------------------------------------------------------
[internal REM command]
----------------------------------------------------------------------
The syntax of the command is incorrect.
C:\GuardPost>REM_Demo ::
----------------------------------------------------------------------
[Commonly used :: technique]
----------------------------------------------------------------------
[1] Before the remarked line
The filename, directory name, or volume label syntax is incorrect.
[2] Before the remarked line
The filename, directory name, or volume label syntax is incorrect.
[3] Before the remarked line
The filename, directory name, or volume label syntax is incorrect.
__________________________________________________ ____________________
[Tue 05/06/2003 01:41:33] End of Script [REM_Demo.cmd]

C:\GuardPost>REM_Demo .Rem
----------------------------------------------------------------------
[Mount/\Command .Rem]
----------------------------------------------------------------------
[1] Before the remarked line
[1] After the remarked line
[2] Before the remarked line
[2] After the remarked line
[3] Before the remarked line
[3] After the remarked line
__________________________________________________ ____________________
[Tue 05/06/2003 01:42:39] End of Script [REM_Demo.cmd]

C:\GuardPost>. ShowComments

C:\GuardPost>REM_Demo .Rem
----------------------------------------------------------------------
[Mount/\Command .Rem]
----------------------------------------------------------------------
[1] Before the remarked line
[1] ***EMBEDDED COMMENT***
[1] After the remarked line
[2] Before the remarked line
[2] ***EMBEDDED COMMENT***
[2] After the remarked line
[3] Before the remarked line
[3] ***EMBEDDED COMMENT***
[3] After the remarked line
__________________________________________________ ____________________
[Tue 05/06/2003 01:42:50] End of Script [REM_Demo.cmd]

*******
Additional details and a color-coded example on the .Rem Page at

(http://TheSystemGuard.com/MtCmds/CrystalClear/Rem.htm)
*******
The commands above are part of the .Mount/\Command Set (over 200
commands) and they perform CONSISTENTLY across NT/2K/XP/K3 as well as
providing self-documenting code for your scripts.

See (http://MountCommands.com) for more information.
*******
Other .Mount/\Commands in the REM_Demo.cmd script are:

.DashLine
.UnderLine

.ExitEL0
.ExitEL1

.dtEcho
*******

Quick List of MountCommands
(http://TheSystemGuard.com/NTCmdLib/MountCommands)

..ExitELn Series
(http://TheSystemGuard.com/MtCmds/ExitELn)

..[Value]Echo Series
(http://TheSystemGuard.com/MtCmds/ValueEcho)

*******

TheGuardBook contains a complete listing of all internal commands common to
NT/2K/XP/K3, including a "Mounted Help Page" highlighting differences among
the platforms.

(http://TheSystemGuard.com/TheGuardBook/CCS-Int)

*******

Notes:

1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
2. .M/\C's are NOT case sensitive. Mixed case is used
for visual clarity only.
3. The (FREE) Advanced NT/2K/XP Command Library (ntlib.cmd),
which also contains the File_Number_Lines (:FNL) Procedure
used above, provides over 50 sample Mount/\Commands to
assist with writing and documenting cross-platform scripts.
You can obtain it (for FREE) at http://ntlib.com.

*******

-tsg
__________________________________________________ __________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!

"William Allen" > wrote in message
...
> "Peter Davies" wrote in message
> > Thnxs once again.
> >
> > I edited the script to include the remote machine, the analyze program
> > opened but came back saying "The command line parameter \data is not a
> > supported option"
> > What would be the next way to work this>? I'm understanding some of the
> > basic flow and logic.
>
> That's really good, because the flow _is_ complicated.
>
> > Seems just short of the goal!
>
> This is how you can work on the problem:
>
> In a complex Batch line, such as this:
>
> "%ROOT%\vss\win32\analyze.exe" -c -d -f -i -v4 %CHILD%
>
> which is built on-the-fly, YOU can see what's happening by ECHO-ing
> it rather than allowing it merely to execute. In the previous line:
>
> SET CHILD="%~1\data"
>
> should set CHILD to the folder specification passed in %1 (the ~ used
> alone removes the "quotes" around it) with the \data folder appended.
>
> It's probable that the CHILD environment variable is not being SET
> correctly, so add an ECHO-ed version of the complex lines, so you
> can watch what's happening:
>
> Start with the %ROOT% line. For example, instead of just:
>
> "%ROOT%\vss\win32\analyze.exe" -c -d -f -i -v4 %CHILD%
>
> use the two lines:
>
> ECHO/ "%ROOT%\vss\win32\analyze.exe" -c -d -f -i -v4 %CHILD%
> "%ROOT%\vss\win32\analyze.exe" -c -d -f -i -v4 %CHILD%
>
> together (keep the ECHO/ & PAUSE breakpoint that comes below)
>
> Then, YOU will see what's being build in CHILD and what CMD.EXE
> is trying to execute. If it looks to you like the wrong command is being
> built up, repeat your detective work with the previous line:
>
> SET CHILD="%~1\data"
>
> making it into two lines:
>
> ECHO/ SET CHILD="%~1\data"
> SET CHILD="%~1\data"
>
> So you see it expanded as CMD.EXE is seeing it. Remember, the
> %~1 should just be whatever is in %1 (but without the any "quotes"
> - see below for where the "quoted" token in %1 comes from)
>
> If the %~1 doesn't expand correctly as you want, you can look back,
> one stage more, at the line
>
> FOR /D %%F IN ("%ROOT%\*.*") DO CALL :_LEVEL1 "%%F"
>
> This line is CALLing the subroutine at :_LEVEL1 repeatedly,
> with "%%F" as the %1 position parameter. And the "%%F"
> is the output of the FOR /D IN DO iteration of D=directories
> with "quotes" around it so that any path containing [Space]s
> that FOR /D IN DO finds is passed as one token (a "quoted"
> string is counted as one chunk to pass in the %1 %2 %3
> Batch system of passing tokens).
>
> That's the way the logic works, and now you're following it,
> use the diagnostic technique of ECHO-ing a complex line
> so that you (and NOT just CMD.EXE) can get to see what
> is happening, and what's going wrong.
>
> That way it should get clearer why the lines expand differently
> for your real data than for the simple test folders we set up here.
>
> Post back with any success/failure.
>
> --
> William and Linda Allen
> Creative Technical Writing - Allen & Company: http://www.allenware.com/
> Free MS-DOS Batch File Course http://www.allenware.com/icsw/icswidx.htm
>
>

Google