Save time with .bat files
If you often type in the same repetitive commands on your CMD, .bat files are a great way to speed up your workflow. Essentially, you can create a .bat file to quickly run a script. For a simple example, if I wanted to build a site with Jekyll, usually I would have to type
set JEKYLL_ENV=production to set Jekyll to build for a production environment, then type out
bundle exec jekyll build to build the site. However, with .bat files, I can simply run the file from the command line and it runs it automatically.
The issue I faced is that I wanted to add the .bat name as a command that I could execute in any folder I wanted. Luckily, this is incredibly easy to do.
- Put all your .bat files into a folder. I put mine into a scripts folder under /documents for easy access.
- Copy the address of the folder.
- Search for environment variables in Windows search. Select the ‘Edit the system environment variables’.
- In the Window that pops up, hit the ‘Environment Variables’ button.
- You should see an option for
Pathlike below. Click on it, and then click ‘Edit’.
- Click ‘New’ on the right side.
- Paste in your address of the folder that you copied in step 2.
Now you are done! You can call your .bat files by typing their names into the CMD.
I use this a lot when working with this blog and a few other Jekyll sites. It lets me serve, and build them, in a second instead of having to type out the command.