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

Hiding a simple batch window

I've searched this and some pages came which weren't really useful or were too complicated (I am not a skilled batch file programmer!)! What I need is to run a batch file in hidden form (no console window). The batch file will not be called from…
Amir Zadeh
  • 3,481
  • 2
  • 26
  • 47
10
votes
3 answers

Visual Studio Build Event Immediately Return

I have a somewhat long-running post-build event (long enough to be annoying to wait for but short enough to be finished after each release compilation) that I want to return immediately to VS. I've tried to run batch files with start but visual…
Max
  • 6,901
  • 7
  • 46
  • 61
10
votes
2 answers

Running a batch script by right clicking any file

The idea is to right click any file and then select "backup" in a drop down that just copies the file and adds a date time to the end of its name, then possibly moves that copy to another drive. I would like a method of running a batch script by…
daniel
  • 471
  • 1
  • 4
  • 13
10
votes
5 answers

Script to start traceroute if continuous ping fails, output to log

I want to continuously ping my home public IP address, and if the ping fails automatically do a traceroute to see where it's failing. I've been trying to follow the comments made…
lysdexic
  • 363
  • 1
  • 3
  • 14
10
votes
3 answers

xcopy all folders and subfolders from txt(with paths , and spaces )

I have a txt file with the full path for .jpg files, I need to xcopy the whole folders including everything inside using xcopy using batch file
massaki
  • 759
  • 2
  • 8
  • 15
10
votes
2 answers

batch file: pass parameter with white spaces to function

I am using a batch file for backups. I pass the options to a function which calls the packaging executable. This works unless the parameters contain whitespaces. This is the relevant code: SET TARGET="%SAVEDIR%\XP.User.Documents.rar" SET…
Matthias Pospiech
  • 3,130
  • 18
  • 55
  • 76
10
votes
3 answers

How to count amount of processes with identical name currently running, using a batchfile

I would like to use a batch file to compare the number of processes named "standard.exe", that are running on my Windows 7 machine, with the number of processes named "basic.exe". If the amount of processes called "standard.exe" equals the amount of…
Sander_
  • 121
  • 1
  • 1
  • 5
10
votes
3 answers

Windows BAT or CMD: send some data to a localhost udp port

I have an app that listens on a localhost port. I want a minimal launcher to bring that app's to the front. My app is in Java. I don't know how to write any exe files, but I can write bat files, and then make a shortcut that launches the bat file…
700 Software
  • 85,281
  • 83
  • 234
  • 341
10
votes
2 answers

convert backslashes to forward in batch files

whats the easiest way of converting all backslashes to forward in a path in a batch file, since I need to use bash for execution.
remo
  • 3,326
  • 6
  • 32
  • 50
10
votes
3 answers

Cannot install sdkmanager in windows 10

I am trying to install the sdk manager alone for using it with Eclipse. I downloaded the zip file provided by google - commandlinetools-win-6200805_latest.zip from https://developer.android.com/studio But as I try to run the sdkmanager.bat file it…
truespan
  • 189
  • 1
  • 2
  • 11
10
votes
2 answers

SQLCMD utility from BAT file - how to return ERRORLEVEL in case of syntax error

How can I get %ERRORLEVEL% from SQLCMD utility when some of .sql files contains syntax error? These files create stored procedures. They don't invoke "raiseerror", but they can conatin syntax error and I need to terminate the process. But it always…
kovalu
  • 129
  • 1
  • 2
  • 9
10
votes
2 answers

Batch delete all files and directories except specified file and directory

I'm trying to delete all files and directories in a specific directory using a bat file in said directory. I've seen this done on Linux without problem, but in Windows command environment it seems to be a chore. Example: \temp\1.bat (keep)…
Jake J
  • 109
  • 1
  • 1
  • 7
10
votes
3 answers

Batch process all files in directory

Right now i have a batch job I wrote that calls another file and passes in the variables that executable needs to run (password and filename). Ex: > cd f:\test\utils > admin import-xml -Dimport.file=f:\DB\file1.xml -Dadmin.db.password=test123 I…
Gabriel
  • 275
  • 2
  • 3
  • 6
10
votes
10 answers

How to stop batch script on del failure

We have a batch script that removes files (del) and directories (rd). Does anyone know how to halt (fail) execution of the script if any of these delete statements fail? They could fail if a file/directory is locked by Windows. …
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429
10
votes
5 answers

windows batch file script to pick random files from a folder and move them to another folder

I need a batch script to randomly select X number of files in a folder and move them to another folder. How do I write a windows batch script that can do this?
techdaemon
  • 215
  • 2
  • 7
  • 13