It goes like this: create a small script that will take the files from a folder (only the top folder, not the sub directories) and will copy them to Program Files (32 bit). How hard can it be?
Well… If you have a programming background and you like to format the code then, such a task takes 1 hour, otherwise… 5 minutes.
So, I wrote a batch file (just part of it displayed here):
SET /P config=Configuration to deploy (1 = Debug; 2 = Release): ECHO Setting up folders... SET instpath = %ProgramFiles(x86)% IF %config% == 1 (set drop = source\bin\x86\Debug) IF %config% == 2 (set drop = bin\x86\Release)
Which is incorrect. Can you spot the mistake?
I will highlight one of the lines for you, maybe you can spot it then.
SET /P config=Configuration to deploy (1 = Debug; 2 = Release): ECHO Setting up folders... SET instpath = %ProgramFiles(x86)% IF %config% == 1 (set drop = source\bin\x86\Debug) IF %config% == 2 (set drop = bin\x86\Release)
Another hint: lines 5, 6 and 7 are incorrect.
Let me fix it and maybe you’ll see the problem.
SET /P config=Configuration to deploy (1 = Debug; 2 = Release): ECHO Setting up folders... SET instpath=%ProgramFiles(x86)% IF %config% == 1 (set drop=source\bin\x86\Debug) IF %config% == 2 (set drop=bin\x86\Release)
Can you see the difference now? Some of you might not…
In BAT files:
SET instpath=%ProgramFiles(x86)%
and
SET instpath = %ProgramFiles(x86)%
are not the same. The first one will set the variable, while the second one will fail (without warning/error). Apparently, there should be no space between the variable name and the equal sign when setting a value.
Microsoft would do a great thing if it would adopt something like bash for its scripting – with the batch files kept as a backwards compatibility. It’s not hard to do, and it would help a lot – you don’t need binary code for stuff like that.
Or, maybe, have something like python always delivered with Windows :) It would really push things forward for Windows programmers :)
Yeah, unfort. SET command is “space-sensitive”, I agree this is the #1 issue for ppl with programming background :)
In order to have better scripting experiences/possibilities in current Windows versions I use Powershell which enables a more programmer-related feeling and access to .NET
$env:instpath = (Get-Item "Env:ProgramFiles(x86)").ValueThough, performing a copy of files is slower in ps then in cmd (of course just with a reasonable amount of files), at least thats my experience :)