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 expressive 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" but for questions related to the shell language only.

Useful links

3066 questions
7
votes
1 answer

Batch file function is executed without being called

I defined a function, the strange thing is that the function lines are executed even if I do NOT call the function !! echo off cls REM call:ctrlService "stop" "1.1.1.1" echo.SERVICES STARTED :ctrlService - Generic function echo.Parameter 1:…
7
votes
3 answers

Batch Script - Parenthesized echo of the word "Where" issue

A while back I asked about Batch Script Redirection Syntax and received a nice answer. I've utilized the parenthesis () method more often to echo in batch scripts and redirect to files, etc. I've run into an odd issue where it appears the word Where…
6
votes
4 answers

How to read from a text file being hosted on a website in a batch file

I want to read the contents of a text file line by line being hosted on a website with a batch file. Ex: from example.com/text.txt I had tried @echo off for /f "tokens=*" %%A in (http://example.com/text.txt) do (echo%%A) But it looks for a file…
5
votes
1 answer

Special characters in batch

I'm using windows 7, and I'd like to create menus, progress bars, etc. with special characters like this. How to do this?
builder_247
  • 341
  • 2
  • 6
  • 14
4
votes
3 answers

Any way to get the first few characters of filename in DOS batch file Programming

I am using this in my program for %%I in (*.txt) do ( The filename is in %%I. Now i want to separate the first 2 chracters, next 3 characters, separately. Is this possible in DOS or Cmd.exe?
Mirage
  • 3,183
3
votes
1 answer

Create Batch file to copy one folder and then generate it 1,000 times naming it 'AE 0001' up to 'AE 1000'

I've had a look around, and I found some stuff that kinda worked, but I'm new to all this batch stuff. I'm looking for a batch script that will copy one folder and everything in it. The folder is called Package Master I then want it to make 1,000…
Kilm
  • 33
3
votes
1 answer

Fire batch (.bat) file execution and continue

I want to write a .bat file that starts executing another few .bat files, without waiting for the 1st to complete before going to the next one. Spawning multiple cmd.exe commands is OK. I tried doing call script1.bat call script2.bat from the…
3
votes
3 answers

Batch file. Variable in variable

How to use variables in variables? This code: set newvar=%var%var2%% doesn't work. So, what to do? I can't write my program without it.
3
votes
4 answers

Batch Script to Create Multiple Folders within Multiple Folders

I have tried a bunch of things and a lot of research but nothing I've tried has done what I need. I'm trying try create a folder structure of multiple folders within another folder. The names of the folders are separated by commas in a batch script…
3
votes
1 answer

What does the last part of set params = %*:"="" do?

I'm working with a batch script that needs admin rights and I borrowed some get-admin-rights code from the 'net. I'm trying to figure out what the last part of a particular line does: set params = %*:"="" I know the first part creates a variable,…
3
votes
4 answers

Get second line of output from command

I have multiple files with the json extension in a directory. These are used to generate some other files but that should only happen if the json files have changed. So far I have the following measly script: for %%f in (*.json) do ( …
2
votes
2 answers

Returning the linenumber of a matching substring in Batch

I want to return the line number in a file that always has the same prefix, but the rest may vary. Is it possible to search a file using only stock Windows components and Commandline operating utilities to return the line number of the matching…
user508617
2
votes
2 answers

BAT file to extract folder name from a file name & move the file into that folder

I'm not very familiar with windows bat file programming and I would appreciate any help with this. I need a bat file to do the following: extract folder name from a filename - eg, extract Chemistry from the filename "123-Chemistry-101.rep". "-" can…
durand
2
votes
1 answer

Batch file - file name extract

I can get the jpg file names extracted to a text file using : for %%a in (*.jpg) do echo %%a >> get_files.txt and this is the output : Seedling-Acacia-Acinacea-Gold-Dust-Wattle-2-months.jpg Seedling-Acacia-Acinacea-Gold-Dust-Wattle-6-months.jpg…
Nick
  • 23
2
votes
2 answers

Find all .mp3 and move to specified directory using batch

How would I change this to find .mp3 and move to specified directory? @echo off set extlist=mkv mp4 mp3 set rootfolder="C:\Users\Fred\Downloads\uTorrent\Downloads\Complete" pushd %rootfolder% if not ["%cd%"]==[%rootfolder%] echo Aborting as unable…
1
2 3
12 13