Автор: Jack McLarney
Издательство: No Starch Press
Год: 2024
Страниц: 580
Язык: английский
Формат: pdf, epub, mobi
Размер: 10.1 MB
In this era of advanced programming languages, the simplicity, universality, and efficiency of Batch scripting holds undeniable value.
A book about bat files? Why? Whether you’re maintaining legacy systems or seeking to understand the foundations of command line automation, The Book of Batch Scripting shows you how to become proficient with this tool included in every version of Windows.
Batch isn’t new, and the lack of some functionality is mystifying by today’s standards, but it’s still an immensely useful language that isn’t going away anytime soon, especially since it’s being packaged with the operating system installed on every Windows computer. While Batch is one scripting language among many, there are still many lines of Batch code being supported by large and small companies, and some tasks truly lend themselves to bat files more than any other language. And as for that lacking functionality—booleans, arrays, hash tables, stacks, even object-oriented design, and more—I’ll show you how to build it yourselves by the end of this book.
But the most immediate reason for me personally to write a book about Batch scripting is that after two decades of writing bat files for personal and professional use, I believe that I’ve gotten to a place where I’ve learned enough about the topic to share my experiences and insights with a larger community. For many moons, I coded at a company that ran large-scale processes on Windows servers, all of them driven by bat files. Others might have gone with a more modern scripting language, but a coder who preceded me had mastered the art of bat files to such an extent that an alternative to Batch was never seriously considered. I played the understudy role of Robin until his retirement, when I was unofficially elevated to Batman.
Writing Batch code is still an important skill for any coder and even noncoders, but much of the existing documentation is sparse, scattered, and sometimes inaccurate. More so than in other languages, a great deal of experience and experimentation is required to gain proficiency, and I have a unique perspective to share. That’s why I wrote this book.
As you work through the book, you will:
Write a simple .bat file that performs a daily task with just a couple of mouse clicks
Delve into variables and data types, and learn how a variable can possess two values at once—and why you should care
Learn how to manage and collect data on files and directories either locally or on a network
Harness the power of the for command to build complex loops with just a few lines of code
Explore advanced topics like recursion, performing text searches, and even learn how to write a .bat file that writes a .bat file
Extend Batch to use features like booleans, floats, operators, arrays, hash tables, stacks, queues, and even object-oriented design
This Book’s Audience:
This book is not for beginners, nor is it for experts; it’s for both. I actually hope to reach three groups of people. The first is coders who write, maintain, or otherwise work with bat files on a near daily basis. The second is all other coders who work on a Windows machine, and the third is noncoders who also work on a Windows computer.
The first group, those working closely with Batch, are on the list for obvious reasons. This book is the culmination of two decades of my intense and immersive work in Batch scripting. By the end of this book, you’ll have explored several complex concepts, such as creating commands, data structures, operators, and even a coding paradigm that weren’t envisioned by the language’s creators. I’ll work steadily up to that complexity, but I hope that in these pages you’ll find everything you need to master the language and the tools to further explore what little isn’t here.
If you’re in the second group, you likely don’t maintain thousands of lines of Batch code, but on a Windows computer you write code in other languages, and you should be at least moderately versed in Batch. This skill allows you to perform some common and repetitive tasks by running a simple (or maybe not so simple) bat file. Animating code written in other languages has its challenges, one of which is that your machine’s environment is different from the eventual production environment where the program will execute. To this end, I’ll show you how to mimic or simulate another computer’s environment with a few lines of Batch code. By the end of this book, I’m sure that you’ll find that a bat file is a solution for many issues.
Even noncoders, the final group, can benefit from some Batch code to minimize repetitive tasks such as moving files, merging reports, or connecting to network drives to make Windows Explorer easier to use. Since coding isn’t in your job description, your employer is unlikely to load the infrastructure for other coding languages onto your computer so that you can perform relatively simple coding tasks, but everything you need to write and execute a bat file is already on your workstation. The skill set needed to write a bat file is the ability to create a text file, rename it, and type a few lines into it. And if you can double-click a file, you can run a bat file. That’s all you’ll need (other than this book).
Скачать The Book of Batch Scripting: From Fundamentals to Advanced Automation