Discussion:
batch file structure
(too old to reply)
Dallas
2022-07-05 12:52:20 UTC
Permalink
When you code a batch file do you have patterns that help when you compose them?

For example I always start off a batch file with a line in the form

@echo off % mybatchfilename.bat %

Note the spaces after the first % and before the final % character.
I put those there just to make sure I don't accidentally match an actual variable name.

That way the content of the batch file carries the name of the batch file.

I am curious if anyone has things like that that help you compose batch files.
Zaidy036
2022-07-05 14:56:44 UTC
Permalink
Post by Dallas
When you code a batch file do you have patterns that help when you compose them?
For example I always start off a batch file with a line in the form
@echo off % mybatchfilename.bat %
Note the spaces after the first % and before the final % character.
I put those there just to make sure I don't accidentally match an actual variable name.
That way the content of the batch file carries the name of the batch file.
I am curious if anyone has things like that that help you compose batch files.
My first line is always:

:: name.bat
Auric__
2022-07-05 16:43:35 UTC
Permalink
Post by Dallas
When you code a batch file do you have patterns that help when you compose them?
For example I always start off a batch file with a line in the form
@echo off % mybatchfilename.bat %
Note the spaces after the first % and before the final % character.
I put those there just to make sure I don't accidentally match an actual variable name.
That way the content of the batch file carries the name of the batch file.
I am curious if anyone has things like that that help you compose batch files.
Not batch files, no. I have a template that I use for the README of my
projects, but nothing for anything scripting- or programming-related. The
majority of my batch files tend to be one-liners anyway.
--
You were warned! Now reap the consequences!
Kerr-Mudd, John
2022-07-05 20:28:03 UTC
Permalink
On Tue, 5 Jul 2022 16:43:35 -0000 (UTC)
Post by Auric__
Post by Dallas
When you code a batch file do you have patterns that help when you compose them?
For example I always start off a batch file with a line in the form
@echo off % mybatchfilename.bat %
Note the spaces after the first % and before the final % character.
I put those there just to make sure I don't accidentally match an actual variable name.
That way the content of the batch file carries the name of the batch file.
I am curious if anyone has things like that that help you compose batch files.
Not batch files, no. I have a template that I use for the README of my
projects, but nothing for anything scripting- or programming-related. The
majority of my batch files tend to be one-liners anyway.
Mostly self-documented with a 'help' section

rem {insert datestamp}
if \%1==\ goto Usage
...



...
goto end
Usage:
echo %0 is a program to ...
echo Usage is %0 parm1 parm2 {parm3}
echo e.g. %0 x y does action
rem relies on (dependency) being accessible via path
--
Bah, and indeed Humbug.
Auric__
2022-07-05 22:00:37 UTC
Permalink
Post by Kerr-Mudd, John
On Tue, 5 Jul 2022 16:43:35 -0000 (UTC)
Post by Auric__
Post by Dallas
When you code a batch file do you have patterns that help when you compose them?
For example I always start off a batch file with a line in the form
@echo off % mybatchfilename.bat %
Note the spaces after the first % and before the final % character.
I put those there just to make sure I don't accidentally match an
actual variable name.
That way the content of the batch file carries the name of the batch file.
I am curious if anyone has things like that that help you compose batch files.
Not batch files, no. I have a template that I use for the README of my
projects, but nothing for anything scripting- or programming-related.
The majority of my batch files tend to be one-liners anyway.
Mostly self-documented with a 'help' section
rem {insert datestamp}
if \%1==\ goto Usage
...
...
goto end
echo %0 is a program to ...
echo Usage is %0 parm1 parm2 {parm3}
echo e.g. %0 x y does action
rem relies on (dependency) being accessible via path
My batches that I use to compress files have help sections, but seeing how
each batch was based on the previous batch (they're named 1z.cmd, 2z.cmd,
etc.) I really only wrote that section once and then modify it as needed for
whatever changes I make.
--
Because in the end, does it really matter?
And why let the truth get in the way of a good story?
Dallas
2022-07-06 15:58:13 UTC
Permalink
Post by Kerr-Mudd, John
Mostly self-documented with a 'help' section
rem {insert datestamp}
if \%1==\ goto Usage
...
...
goto end
echo %0 is a program to ...
echo Usage is %0 parm1 parm2 {parm3}
echo e.g. %0 x y does action
rem relies on (dependency) being accessible via path
Seeing your line coded as

if \%1==\ goto Usage

makes me curious as to how others code that.
I have been using

if [%1]==[] goto Usage:

because it reads well (to my eyes anyway)

Note that I also tack on a colon ( : ) after a label like Usage: in a goto statement just so it
perfectly matches the label to jump to.
Kerr-Mudd, John
2022-07-06 16:49:42 UTC
Permalink
On Wed, 6 Jul 2022 10:58:13 -0500
Post by Dallas
Post by Kerr-Mudd, John
Mostly self-documented with a 'help' section
rem {insert datestamp}
if \%1==\ goto Usage
...
...
goto end
echo %0 is a program to ...
echo Usage is %0 parm1 parm2 {parm3}
echo e.g. %0 x y does action
rem relies on (dependency) being accessible via path
Seeing your line coded as
if \%1==\ goto Usage
makes me curious as to how others code that.
I have been using
because it reads well (to my eyes anyway)
Note that I also tack on a colon ( : ) after a label like Usage: in a goto statement just so it
perfectly matches the label to jump to.
Yes that's better. I merely changed from my older pre-NT batch style of

if "%1 == "

that used to work, and haven't moved on since.
--
Bah, and indeed Humbug.
Dallas
2022-07-06 18:59:30 UTC
Permalink
... The
majority of my batch files tend to be one-liners anyway.
How do you code a batch one-liner ?

I can't remember coding any one-liners.
Auric__
2022-07-06 20:59:10 UTC
Permalink
Post by Dallas
Post by Auric__
The majority of my batch files tend to be one-liners anyway.
How do you code a batch one-liner ?
I can't remember coding any one-liners.
Like this:

dir/a-d/b/s|find /v /i ".mp3">\list.txt

or this:

D:\Wintools\Programming\tcc\tcc.exe *.c

or this:

for %%x in (*.baf) do AICompile FILE %%~nx.baf %%~nx.err %%~nx.bcs

or even just:

del *.bak

All of them almost exclusively ran from the GUI, not the command line.


I generally use batch files as scripts, not complete programs.
--
Three angels follow me. The bright one bleeds power.
The dark one bleeds will. The smallest merely weeps.
Dallas
2022-07-07 15:19:28 UTC
Permalink
Post by Auric__
Post by Dallas
Post by Auric__
The majority of my batch files tend to be one-liners anyway.
How do you code a batch one-liner ?
I can't remember coding any one-liners.
dir/a-d/b/s|find /v /i ".mp3">\list.txt
D:\Wintools\Programming\tcc\tcc.exe *.c
for %%x in (*.baf) do AICompile FILE %%~nx.baf %%~nx.err %%~nx.bcs
del *.bak
All of them almost exclusively ran from the GUI, not the command line.
I generally use batch files as scripts, not complete programs.
What did you name those batch files?

How do you run a batch file from the GUI ?
Auric__
2022-07-07 16:22:04 UTC
Permalink
Post by Dallas
Post by Auric__
Post by Dallas
Post by Auric__
The majority of my batch files tend to be one-liners anyway.
How do you code a batch one-liner ?
I can't remember coding any one-liners.
dir/a-d/b/s|find /v /i ".mp3">\list.txt
D:\Wintools\Programming\tcc\tcc.exe *.c
for %%x in (*.baf) do AICompile FILE %%~nx.baf %%~nx.err %%~nx.bcs
del *.bak
All of them almost exclusively ran from the GUI, not the command line.
I generally use batch files as scripts, not complete programs.
What did you name those batch files?
find-non-mp3s.bat
compile-tcc.bat
cmp.bat
killbaks.bat (although if I had to type it out, it'd probably be 'kbk.bat')
Post by Dallas
How do you run a batch file from the GUI ?
Just like anything else in the GUI, double-click it, or select it and press
Enter. The batch is run from the directory it's in, unless you make a .lnk
(or .pif) with a different "Start in" directory.

- 'find-non-mp3s.bat' was run in the top level of my Music directory
- 'compile-tcc.bat' is run in whatever dir contains C files I need compiled
- 'cmp.bat' is for a game mod I was working on, a long time ago
- a copy of 'killbaks.bat' exists in every directory I have where .bak files
are regularly created that I don't want to save
--
You regard an indecision as a mistake?
Dallas
2022-07-07 16:34:49 UTC
Permalink
Post by Auric__
Post by Dallas
Post by Auric__
Post by Dallas
Post by Auric__
The majority of my batch files tend to be one-liners anyway.
How do you code a batch one-liner ?
I can't remember coding any one-liners.
dir/a-d/b/s|find /v /i ".mp3">\list.txt
D:\Wintools\Programming\tcc\tcc.exe *.c
for %%x in (*.baf) do AICompile FILE %%~nx.baf %%~nx.err %%~nx.bcs
del *.bak
All of them almost exclusively ran from the GUI, not the command line.
I generally use batch files as scripts, not complete programs.
What did you name those batch files?
find-non-mp3s.bat
compile-tcc.bat
cmp.bat
killbaks.bat (although if I had to type it out, it'd probably be 'kbk.bat')
Post by Dallas
How do you run a batch file from the GUI ?
Just like anything else in the GUI, double-click it, or select it and press
Enter. The batch is run from the directory it's in, unless you make a .lnk
(or .pif) with a different "Start in" directory.
- 'find-non-mp3s.bat' was run in the top level of my Music directory
- 'compile-tcc.bat' is run in whatever dir contains C files I need compiled
- 'cmp.bat' is for a game mod I was working on, a long time ago
- a copy of 'killbaks.bat' exists in every directory I have where .bak files
are regularly created that I don't want to save
I just now noticed that none of the one-liners has any arguments.
The %1 %2 %3 ... arguments.
So, running by double clicking makes more sense to me now.

I suppose if you did need arguments you could prompt for them as the batch file ran.
Auric__
2022-07-07 20:00:42 UTC
Permalink
Post by Dallas
I just now noticed that none of the one-liners has any arguments.
The %1 %2 %3 ... arguments.
So, running by double clicking makes more sense to me now.
I suppose if you did need arguments you could prompt for them as the batch file ran.
All of my batches that require arguments are rather longer than one line.
There is a method to pass arguments via a .lnk and/or .pif, but I no longer
remember how. (Haven't needed it in... 15 years? Longer?)
--
Such a pity. How much grander and more powerful you could have still
become. If you've but had the temerity to embrace the path set before you.
Grant Taylor
2022-07-09 01:15:37 UTC
Permalink
Post by Dallas
I suppose if you did need arguments you could prompt for them as the batch file ran.
You should be able to get a batch file to respond to files drug and
dropped onto it's icon.

I used to have some batch / command files for converting / compressing
things. I think I even put a shortcut in the Send To menu on one of my
systems when I was doing a LOT of things.
--
Grant. . . .
unix || die
Ammammata
2022-07-15 10:03:21 UTC
Permalink
Il giorno Wed 06 Jul 2022 08:59:30p, *Dallas* ha inviato su
Post by Dallas
How do you code a batch one-liner ?
batch file - How do I run two commands in one line in Windows CMD? - Stack
Overflow
https://stackoverflow.com/questions/8055371/how-do-i-run-two-commands-in-
one-line-in-windows-cmd

In MS-DOS 5.0 and later, through some earlier Windows and NT versions of
the command interpreter, the (undocumented) command separator was character
20 (Ctrl+T) which I'll represent with ^T here.

dir ^T echo foo
--
/-\ /\/\ /\/\ /-\ /\/\ /\/\ /-\ T /-\
-=- -=- -=- -=- -=- -=- -=- -=- - -=-
........... [ al lavoro ] ...........
Harry Potter
2022-07-21 17:54:05 UTC
Permalink
Hi! I use batch files a lot and have a simple, empty batch file, as follows:
------------
@echo off
-------------
When I need a new batch file, I use Template Creator and this or another template to start my batch files. I have a DOS laptop at my mother's house with the JAM disk compressor installed. Since JAM doesn't automatically mount disks, I use batch files to mount floppies and run the programs on them. It would be easier to create a batch file to copy such files to the floppies, but Template Creator for DOS can do the job. On my WIn98SE system at my mother's house, AppZip doesn't work properly, so I use 7Zip and batch files to temporarily decompress programs on the hard drive. If you want Template Creator, just ask, and I'll provide the URL.
Clif McIrvin
2022-09-18 01:33:28 UTC
Permalink
Post by Grant Taylor
You should be able to get a batch file to respond to files drug and
dropped onto it's icon.
Drag and drop shows up as %1 (or more precisely %* )
Also parameters supplied via .lnk show up as command line parameters.
I don't recall what happens if you drop a file onto a shortcut that includes parameters.

Timo Salmi's excellent FAQ has lots and lots of examples and explanations.
I just saw a link in another recent thread.
Dallas
2022-09-18 14:56:46 UTC
Permalink
Post by Clif McIrvin
Timo Salmi's excellent FAQ has lots and lots of examples and explanations.
I just saw a link in another recent thread.
http://www.elisanet.fi/tsalmi/info/tscmd.html

Loading...