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

Unzip tar.gz in Windows

I would like to unzip Filename.tar.gz to Filename using single command in windows batch script All the files inside zip should go inside the Filename Folder I am trying to do in windows . I am not getting correct output. Can anyone suggest an idea
Nirmal Anand
  • 307
  • 1
  • 4
  • 14
10
votes
1 answer

Can you convert a .sh file to a .bat file?

I need to convert a .sh file to a .bat file so that it can run on windows I was wondering if there is a way to do so? Here is the code i want to convert: export ANDROID_SDK=C:\Users\Spencer Von Der…
user3558582
10
votes
4 answers

How to Sign ClickOnce with Sha256 Cert for .NET 4.0 like Visual Studio Update 3

I am trying to deploy an outlook add-in using a clickonce installer. I have a batch file that almost works, however, I get the error "xml signature is not valid" when trying to install on Windows XP. It is pretty well known that XP fails with SHA256…
OtotheA
  • 513
  • 4
  • 12
10
votes
5 answers

Batch file script to remove special characters from filenames (Windows)

I have a large set of files, some of which contain special characters in the filename (e.g. ä,ö,%, and others). I'd like a script file to iterate over these files and rename them removing the special characters. I don't really mind what it does, but…
njr101
  • 9,499
  • 7
  • 39
  • 56
10
votes
2 answers

Save the output of a powershell command in a variable and use it in batch script?

What I am trying to do is to save the output of a powershell command (run from a batch script) and use it in the batch script. Can you please advise me what to do? The power shell comand is: [System.Net.Dns]::GetHostByName((hostname)).HostName I…
fanciulla
  • 175
  • 1
  • 5
  • 18
10
votes
2 answers

IF, CALL, EXIT and %ERRORLEVEL% in a .bat

Can anyone please help me understand the behaviour of %ERRORLEVEL% variable and why it's not being set after a CALL while being inside an IF, i.e. the ECHO %ERRORLEVEL%.2 line? @ECHO OFF SET ERRORLEVEL VERIFY > NUL ECHO %ERRORLEVEL%.0 IF ERRORLEVEL…
Ilya Kozhevnikov
  • 10,242
  • 4
  • 40
  • 70
10
votes
2 answers

xcopy wildcard source folder name to destination

I want to copy from a wildcard source folder to a destination folder: xcopy a:\parentfolder\n* x:\parentfolder Only folders starting with "n" should therefore be copied to the destination. Any help to get this working would be much appreciated.
Wonderer
  • 113
  • 1
  • 1
  • 6
10
votes
2 answers

Reading a specific line in a text file to a variable in a batch file

In one of my batch files I'm attempting to write, I need to read the last line in a 5 line text file into a variable. One way I thought of doing this might be to have each line that is put into the text file overwrite the previous (as the files…
user2997654
  • 157
  • 2
  • 2
  • 6
10
votes
5 answers

how to use goto in batch script

I have written following code setlocal set /A sample =1 :first type C:\test.txt | find "inserted" if %ERRORLEVEL% EQU 0 goto test if %ERRORLEVEL% EQU 1 goto exam :test echo "testloop" >> C:\testloop.txt set /A sample = %sample% + 1 if…
Bharath
  • 665
  • 5
  • 12
  • 20
10
votes
2 answers

How I get the position of a character from a string in batch

I have a result string saved in a variable RES, this result is something like 2.3/5.0 I would like to get the part before the "/" and sending it to the batch output through an ECHO command. I have been searching how can I do this using batch…
yosbel
  • 1,711
  • 4
  • 20
  • 32
10
votes
3 answers

getting process ID of exe running in Bat File

I require the Process id of the "Las2xyz" process that's being run in my bat file. How can i achieve this? I can't use the last RUN ID or the first ID, I need the actual process ID, as there are multiple of these running at any given time and ending…
Dean
  • 499
  • 6
  • 13
  • 34
10
votes
1 answer

How to show extraction progress of 7zip inside cmd?

7z.exe do not show any extraction progress in cmd."C:\Program Files\7-Zip\7zG.exe" -y x -pPASSWORD "D:\Myfile.rar" Extracts the file with a GUI progress-bar. But I don't want a GUI progress bar. I want to show the progress in terms of percentage…
Deb
  • 5,163
  • 7
  • 30
  • 45
10
votes
5 answers

Coding a real time progress bar in batch

I want to use a real time progress bar where it updates as code is written or installing something or loading a file. Example: @echo off :main echo Updating file... [PROGRESS BAR HERE] The "PROGRESS BAR HERE" indicates the part that I want the…
MegaRodeon
  • 315
  • 2
  • 3
  • 10
10
votes
2 answers

What does :/= mean in %date:/=%?

While searching for a way to create a date-named directory in Windows, I came accross this question with that accepted answer. There's a comment below the accepted answer: To make it more easy: mkdir %date:/=% So, %date% prints the current date,…
eckes
  • 64,417
  • 29
  • 168
  • 201
10
votes
3 answers

How to convert a tasklist's CPU time to CPU % usage?

I'm trying to use tasklist to find out which process is consuming more than X percent of my CPU (to later kill it with taskkill.) How do I know what percent a time format represents? The documentations says: TASKLIST options /FI filter …
OscarRyz
  • 196,001
  • 113
  • 385
  • 569