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

HOW to EXIT using "start" in batch files of MSDOS

I want to copy some files into diffent USB disks, and want to use START to open several consoles as follows: start copy a.txt h: start copy a.txt i: start copy a.txt j: But everytime I run the batch file, there are 3 consoles without exiting. How…
little白
  • 203
  • 2
  • 4
  • 10
9
votes
2 answers

Testing for file attribute in batch file

I'm writing a batch file and I need to know if a file is read only. How can I do that ? I know how to get them using the %~a modifier but I don't know what to do with this output. It gives something like -ra------. How can I parse this in batch file…
Eric Fortin
  • 7,533
  • 2
  • 25
  • 33
9
votes
5 answers

DOS batch FOR loop with FIND.exe is stripping out blank lines?

This DOS batch script is stripping out the blank lines and not showing the blank lines in the file even though I am using the TYPE.exe command to convert the file to make sure the file is ASCII so that the FIND command is compatible with the file. …
djangofan
  • 28,471
  • 61
  • 196
  • 289
9
votes
2 answers

Delete both: hidden and normal files with cmd

Following line recursively deletes only HIDDEN files with .mta extension del /S /A:H *.mta What I want to do is, to delete both: hidden and normal files with .mta extension. How to do it?
Tural Ali
  • 22,202
  • 18
  • 80
  • 129
9
votes
2 answers

my.bat not recognized as an internal or external command, operable program or batch file

When I logon to this Windows 2008 R2 Server and launch a CMD window, the default directory is: C:\Users\SVC_asl2trim> So I added this to the PATH and then I issued: C:\Users\SVC_asl2trim>set…
John Adams
  • 4,773
  • 25
  • 91
  • 131
9
votes
3 answers

Focus a batch-started application

I am running a sequence of applications from a batch script and I want to make sure, that the opened program will always be in focus. We need to ensure this because it's an experimental setup and we want to minimise such hassles as having to change…
Milla Well
  • 3,193
  • 3
  • 35
  • 50
9
votes
2 answers

How can a batch script do the equivalent of "cat << eof"?

In Linux (Bash) there is a very useful functionality for dumping literal text out to another file like this: cat > see.txt << EOF contents going into my file EOF What I need is the equivalent for a Windows batch script. I haven't found this kind…
Jared
  • 1,887
  • 3
  • 20
  • 45
9
votes
7 answers

Save and Load .bat game

I'm making a text game written in bat, and the game has been done, (or more, a good part of it, such as the commands, and at the stage where you can play it); however, I want to add the power to save your game, and load it again. I think one could…
Gareth Jones
  • 1,241
  • 4
  • 17
  • 38
9
votes
3 answers

Can we run a batch file (.bat) from the shared path

I have a shared path (like //servername/c$/batches/) where all my batch files are located now I am writing an web application in C# to run .bat files from that application. I know way to do it when I have a physical path. But here I dont have a…
Praneeth
  • 2,527
  • 5
  • 30
  • 47
9
votes
6 answers

Passing a multi-line string as an argument to a script in Windows

I have a simple python script like so: import sys lines = sys.argv[1] for line in lines.splitlines(): print line I want to call it from the command line (or a .bat file) but the first argument may (and probably will) be a string with multiple…
Zack The Human
  • 8,373
  • 7
  • 39
  • 60
9
votes
2 answers

Background processes in batch with redirected output

I'm trying to run several background processes from a batch file and have the output directed to a file. Is it possible to do this in Windows? This is what I've tried but it end up directing the output of the start program rather then background…
darckeen
  • 960
  • 2
  • 12
  • 20
9
votes
4 answers

How can I read multiple files from multiple directories into R for processing?

I am running a simulation study and need to process and save the results from several text files. I have the data organized in such a way where there are sub directories and within each sub directory, I need to process and get individual results for…
Stefanie
  • 91
  • 1
  • 1
  • 2
9
votes
5 answers

Check if computer is plugged into AC power in batch file

How can I check if computer is plugged into AC power in a batch file in windows 7, like on_ac_power does in linux?
Jakob Weisblat
  • 7,450
  • 9
  • 37
  • 65
9
votes
3 answers

Using an OR in an IF statement WinXP Batch Script

Is there a way to pass an OR through an IF statement? Such as: SET var=two IF "%var%"=="one" OR "two" OR "three" ECHO The number is between zero and four.
Anthony Miller
  • 15,101
  • 28
  • 69
  • 98
9
votes
4 answers

Find out if file is older than 4 hours in Batch file

Quite simply, how would I find out if a specific file in a folder is older than X hours? The file name and location will always be the same. Thanks
user270370
  • 151
  • 1
  • 3
  • 8
1 2 3
99
100