Skip to content

A collection of example batchfiles for Windows, including an explanatory wiki

License

Notifications You must be signed in to change notification settings

rbaltrusch/batch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License: MIT

Windows Batchfiles

This repository is a collection of Windows batchfiles, primarily to practice batchfile syntax and test the various batch functionality available.

The targeted audience of this repository primarily is developers just getting started writing batchfiles. For developers only needing to accomplish simple tasks in the command line window, the common workflow wiki page should be enough to get started.

Contents

This repository contains files that test out:

A more detailed description of most concepts touched on here can be found in the wiki.

In-built Commands

  1. batch_training.bat
    • Showcases a number of common built-in batchfile commands, such as echo, cd, dir and md. Note that this file is not meant to be run and only is a batch file to contain proper syntax highlighting. It exits early in case it is run.

Functions

  1. function.bat
    • Showcases functions with local and global scope.
  2. function2.bat
    • Showcases a function with mixed scope.
  3. function3.bat
    • Showcases a function with local scope and a return value passed back to global scope, using the syntax:
	setlocal
	set /a var_from_local_scope=1
	endlocal & set var=%var_from_local_scope%

Loops

  1. for_test.bat
    • Showcases the for keyword, with its various switches ( /l, /d, /r, /f ).
  2. for_with_label.bat
    • Showcases a for loop using goto labels.
  3. while_test.bat
    • Showcases a while loop using goto labels.

Other

This section contains various other scripts, including conditional statements, user input, file redirection (piping), and other functionality.

  1. choice_test.bat
  2. conditionals.bat
  3. delayedexpansion.bat
  4. delayedexpansion_without_setlocal.bat
  5. input_test.bat
  6. random_number.bat
  7. redirection.bat
  8. script_with_args.bat
  9. string_substitution.bat
  10. substring.bat

Getting started

To get a copy of this repository, simply open up git bash in an empty folder and use the command:

	$ git clone https://github.com/rbaltrusch/batch

Contributions

Any contributions, such as additional features, bugfixes, or documentation are much appreciated. Contribution guidelines are specified in CONTRIBUTING.md.

License

This repository is open-source software available under the MIT license

Contact

Please raise an issue for code changes. To reach out, please send an email to richard@baltrusch.net.

About

A collection of example batchfiles for Windows, including an explanatory wiki

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks