Questions tagged [batch-file]

A batch file is a text file containing a series of commands that are executed by the command interpreter on MS-DOS, IBM OS/2, or Microsoft Windows systems.

Batch files are text-based scripts, usually saved with the .bat, .cmd, or .btm filename extension. They are executed by the command processor (typically COMMAND.COM on MS-DOS and earlier versions of Windows, cmd.exe on IBM OS/2 and later version of Windows). Note that, while batch files are still supported under Windows, recent versions have the much more expansive PowerShell.

Example

This is the source code to a typical "Hello world" program in batch programming:

@ECHO off
ECHO Hello World!
PAUSE

Note the ! may not display if delayed expansion is enabled.

Tag usage

The tag can be used for programming-related problems in writing a batch script file for a Windows-based operating system. Please avoid "suggest a book"-type questions. Note the tag is not to be used for questions referring to a "batch of files" or referring to the "Spring Batch" framework but for questions related to the shell language only.

Useful links

See also:

53766 questions
10
votes
3 answers

In cmd.exe, how can you get one variable to escape the setlocal command?

I frequently find myself using setlocal within cmd.exe to avoid polluting the environment variable space with temporary variables (and to ensure both command extensions and delayed expansion are active). However, I'm at a loss on how to do this if I…
paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
10
votes
1 answer

7-zip command line - Incorrect wildcard type marker

I'm using 7-zip 15.14 64-bit on Windows 10. I have a batch file that compiles a game I'm working on, only problem is I get an error about an "Incorrect wildcard type marker". Here is the line of code taken right from the batch…
Eduardo Perez
  • 503
  • 7
  • 22
10
votes
5 answers

Loop through ASCII codes in batch file

How do I loop through ASCII values (here, alphabets) and work on them? I want to echo A to Z without having to type every character manually like for %%J in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do echo %%J So I was wondering if I…
Rishav
  • 3,818
  • 1
  • 31
  • 49
10
votes
2 answers

Batch file stops executing after mvn command

set homepath=%userprofile% set a=%1 set b=%2 set c=%3 set uuid=%4 set zipDirectory=%5 set pluginDirectory=%6 cd %homepath%\%a% mvn archetype:generate -DarchetypeCatalog=file://%homepath%/.m2/repository Everything works up to here, then the command…
Martin Erlic
  • 5,467
  • 22
  • 81
  • 153
10
votes
2 answers

How to get the number of batches in preparedstatement?

I think this must be easy. There must be some method for this. This is what i want:- PreparedStatement ps = ... ps.addBatch ( ); ps.addBatch ( ); ps.addBatch ( ); logger.info ( "totalBatches: " + ps.someMethod() ); ps.executeBatch ( ); result…
Rakesh Juyal
  • 35,919
  • 68
  • 173
  • 214
10
votes
2 answers

Special Characters in Batch File

Special characters in batch files are a pain, but I haven't found the right workaround for properly escaping the first two characters of this particular string I'm trying to pass the application. SET pass=^&AntiBatchfileString A_Program.exe…
Matthew Rhoden
  • 688
  • 1
  • 10
  • 20
10
votes
2 answers

Concatenating strings and variables in batch

I would like to create a dynamic file path in .bat file. At the moment the file path looks like this: "C:\FolderA\FolderB\FileA.xlsx" I would like to incorporate today's date in the file name to produce something like…
ProtoVB
  • 773
  • 5
  • 12
  • 24
10
votes
2 answers

MSDOS prints the whole batch file on screen instead of executing

Whenever I try to execute a batch file, even a simple one, it prints the whole thing out instead of executing it. I have tried it on MS-DOS 3.3 and 4.0, both do this. If I execute each command individually in the command prompt though they work (so…
Narwhal88
  • 101
  • 3
10
votes
2 answers

What does %date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2% mean?

I have this part of script that create a variable called fileName used later to name a file. set fileName=db_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%.bak What does %date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%…
LightTechnician
  • 277
  • 1
  • 4
  • 14
10
votes
3 answers

How to make for loop in windows batch file run in name order

I have a windows batch file that does this: for %%s in (*.sql) do call It loops through all the sql script in a folder. In the folder the file names are like: s4.06.01.sql s4.07.01.sql s4.08.01.sql s4.10.01.sql s5.01.sql But the for loop goes…
newguy
  • 5,668
  • 12
  • 55
  • 95
10
votes
1 answer

Batch File and Quoting Variables

I'm working with a batch file and I was wondering, why do some variables have double quotes around them and others don't, for example? SET "keePass=%USERPROFILE%\KeePass\KeePass-2.31\KeePass.exe" but this: SET name="bob" Why the double quotes in…
user5910494
10
votes
2 answers

Windows Batch file launch a gui with buttons

How can I create a window with multiple buttons in which do not go away apon clicking them. I'm trying to make a simple Windowed Box with buttons that can open programs. I've been using WBox.exe for my gui, however it closes the window before the…
Zombie Waffles
  • 175
  • 1
  • 2
  • 12
10
votes
2 answers

Move folder from one directory to another in batch script

Can anyone please tell me how to move a folder from one path to another path using batch script? For example, I want to move XXX folder (including the contents) from D:\abc\XXX folder to D:\cef\.
orbit
  • 101
  • 2
  • 2
  • 6
10
votes
4 answers

Why doesn't "set -P" work after a pipe?

C:\>type c:\output.txt abcd C:\>type c:\output.txt | set /p V1= C:\>set ... A bunch of junk, NOT seeing "V1" What happened? According to all documentation for SET I've seen, %V1% should have been assigned a value of "abcd" from the above, no? I'm…
DVK
  • 126,886
  • 32
  • 213
  • 327
10
votes
3 answers

Calling PowerShell from batch, and retrieving the new value of a temporary environment variable set in the script?

I hope the title is concise, but just in case: I am calling a PowerShell script from a batch file. I want the PowerShell script to set the value of an environment variable, and for that new value to be available in the batch file when the PowerShell…
Nicholas Hill
  • 221
  • 1
  • 2
  • 5