Handmade Hero»Forums»Code
22 posts
Batch File Programming
Edited by Bits Please on Reason: Initial post
What's crackin' everybody?
It seems to be very beneficial to master batch file programming. The more I learn it, the more powerful I become as a programmer.
Unfortunately, there aren't any good resources out there on this topic... Is it because it's not as good as it seems to be, or is it just because not many programmers are familiar with this kind of approach to programming?
Also, it would be very nice of you if you could share some good resources on the matter and enlighten me!

Thanks!
Mārtiņš Možeiko
2559 posts / 2 projects
Batch File Programming
Its because nowadays most serious bat-file scripts migrated to powershell. That said, I hate powershell, I still do most simple scripts in .bat. If I need to do something more serious, Python is my choice.

As for how to learn .bat file scripts, I don't really know. All information I need I get from builtin help commands:
1
2
3
4
5
6
7
for /?
if /?
set /?
cmd /?
echo /?
goto /?
etc...

That is enough for me.
22 posts
Batch File Programming
Hmm I see, if so then, what's the problem with powershell, and in general, what's the difference between powershell scripts and bat-file scripts, is there anything you can accomplish with powershell that is not possible with a batch file?
Mārtiņš Možeiko
2559 posts / 2 projects
Batch File Programming
Yes, a lot. Powershell can instantiate COM objects or call C# code in .NET libraries.

I don't like it because it is too verbose to type for simple things. How do you get list of files in cmd.exe? "dir c:\folder". How do you do that in PS? "Get-ChildItem -Path C:\folder". Much more to type.

PS feels more like generic purpose programming language than small scripting thing on CLI.
117 posts
Code hacker/developer
Batch File Programming
Yeah PowerShell is awkward honestly... But they do have default aliases for several unix commands like ls or pwd for example. You could make more aliases if you wanted to shorthand PowerShell... It's definitely powerful but as Martins said, pretty verbose...

It follows a model where everything is an "object" basically. Dude check this site out: https://www.tutorialspoint.com/batch_script/ and this: https://ss64.com/nt/

Thank me later :D
50 posts
Batch File Programming
Todd, thats a great tutorial and reference.

I agree you should definitely master any batch programming to become better developer, python might be one great alternative. It will depend also whom you are working for and what are your restrictions.

I am dropping you another option, win-bash, specially if you come from a linux background and you are developing in windows. But notice I have only used this option at home, and not professional projects. Might have its cons.