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
2 answers

To delete folder starting with a same starting characters

I need to delete folders in a folder in one shot, and this folders start with a common name, but does not end with. So any command with del/rm to do this? I tried with wildcards but that didn't work. c:\temp> rmdir hello* --- directories with…
Srikanth Yadake
  • 533
  • 2
  • 11
  • 25
10
votes
2 answers

How do I create a batch file to search for file(s) with certain extension within a folder?

Please help! I an new to creating batch files. I am trying to create a batch file to do the following things : Search for file(s) with a certain file extension (i.e. .docx) within a folder Output both filename(s) and extension to a text file…
user2387527
  • 101
  • 1
  • 1
  • 3
10
votes
3 answers

How to open BAT (windows batch) file in Eclipse?

How to open BAT (windows batch) file in Eclipse? When I am doing Open File... the file runs, not opens. How to open it in editor? Dragging file on Eclipse also runs it.
Suzan Cioc
  • 29,281
  • 63
  • 213
  • 385
10
votes
4 answers

How to create a shortcut to launch an App with admin privileges from the cmd-line?

I have an installer (Inno-Setup) that installs my application to a path defined by the user. At the end of the install routine i want to create a shortcut that starts the application with admin privileges. The solution should work on all win version…
Chriss
  • 5,157
  • 7
  • 41
  • 75
10
votes
7 answers

A batch file to minimize other applications

How can i have a bat file which opens an application lets call it firefox.exe.how would i call the bat file or any other script ie vbs to minimize the application ie firefox.exe then after lets say a minute or two close it.please mind you the…
Jimmy Obonyo Abor
  • 7,335
  • 10
  • 43
  • 71
10
votes
1 answer

How to Batch change file extensions within subfolders

I am very new to Command Prompt, and only started using it as of 1 day ago. I have a folder in a location, for example C:\Users\Administrator\Desktop\Images, and inside that folder there is roughly 650 sub-folders, each containing around 20 images,…
Jai Burrell
  • 101
  • 1
  • 3
  • 6
10
votes
2 answers

windows %PATH% variable - how to split on ';' in CMD shell again

I just checked stackoverflow that seemed to be very helpful and worked fine on Windows XP. But using Windows 7 it does not work for some obscure reason. The PATH variable looks like this C:\Program Files (x86)\NVIDIA…
Christian
  • 133
  • 1
  • 2
  • 7
10
votes
2 answers

replace a character in the string using DOS commands

I have a requirement in which I need to replace particular character from a string, by using a DOS command. For example, if my string is "1,2,3,4", I need to get the result "1.2.3.4" by replacing each "," with a "." character.
Raveendra M Pai
  • 445
  • 2
  • 10
  • 27
10
votes
4 answers

How to remove an environment variable from the system configuration with a batch file

I need to remove system variables from client workstations. I have 500+ clients, so I want to provide batch file to user to run himself to delete the system variables.
user73628
  • 3,715
  • 5
  • 29
  • 24
10
votes
5 answers

cmd: if exist A and B then

What is the simplest and/or most readable method to IF with AND in a CMD shell? In pseudo code: IF EXIST file1 AND file2: then do stuff ELSE: do something else this Q has to be somewhere on SO but my search-fu isn't working for this one.…
matt wilkie
  • 17,268
  • 24
  • 80
  • 115
10
votes
7 answers

How to execute a batch file from java?

I want to execute a batch file from a java program. I am using the following command. Runtime.getRuntime().exec("server.bat"); But the problem is I want to give a reative path instead of absolute path so that I can deploy that java project on any…
Amit
  • 33,847
  • 91
  • 226
  • 299
10
votes
1 answer

how to call / run multiple python scripts from batch file in window xp / 7

I'm trying to schedule run multiple pythons using batch file. For example there are my python files that I want to schedule run them on the daily basis D:\py\s1.py D:\py\s2.py now how can I combine these two files into a .bat, so that I can…
JPC
  • 5,063
  • 20
  • 71
  • 100
10
votes
2 answers

How do I transform the working directory into a 8.3 short file name using batch?

I'm writing a build script, and if the directory the user's building the script contains spaces, everything falls apart. To go around that, I thought of using 8.3 filenames so that drive:\Documents and setttings\whatever becomes…
Geo
  • 93,257
  • 117
  • 344
  • 520
10
votes
2 answers

Command for opening serial port in Windows 7

Is there a Windows command for opening serial ports, say COM3 via the command prompt in Windows 7? For example: OPEN "COM6" AS #1 I cannot use pyserial or any other utilities that are not distributed with Windows 7. Preferred solution Opening a COM…
Olumide
  • 5,397
  • 10
  • 55
  • 104
10
votes
5 answers

Expect-like tool for windows

I am searching for a tool that behaves similarly to Unix's expect tool (or at least, its main function). I want to automate command-line interactive programs with it. EDIT: I am preferring single executables or small apps without big multi…
majkinetor
  • 8,730
  • 9
  • 54
  • 72