I first wrote the script to loop though multi-disc images and process them separately, then move them to a temporary directory and process everything that was left. I have that script working perfectly. However, I wanted to streamline it by simply having it detect whether the filename has "(Disc " in it and process it accordingly. That's where everything went wrong.
For some reason, the script fails on an IF comparison with an error based on the filename having something enclosed both in parenthesis and brackets. However, when I change the commands AFTER that line, no more error.
An example filename that causes a problem is;
Some Program (test) [new].iso
To simplify things, I've added the example filename right to the scripts for testing.
I can post the entire script if you want, but it's kind of long and confusing. Here's the part that doesn't work with that filename;
This generates the error "[new] was unexpected at this time." and the PAUSE command is never executed. However this does NOT generate an error;
Code: Select all
@echo off cls set Name=Some Program (test) [new] set Ext=.iso call :Process ) goto end :Process if "%Name%"=="%Name:(Disc =%" ( pause set Pattern=%Name% set Archive=%Name% exit /b ) :end
Obviously this doesn't do anything, but most importantly it doesn't generate an error! It executes PAUSE and then exits the routine.
Code: Select all
@echo off cls set Name=Some Program (test) [new] set Ext=.iso call :Process ) goto end :Process if "%Name%"=="%Name:(Disc =%" ( pause exit /b ) :end
To further confuse the issue, if I remove "(test)" from the filenames, then the "[new]" doesn't generate an error.
I'm at a complete loss for for what's going on here. Except for the parts that were changed, I literally copied and pasted the code from the script that fails to the script that doesn't fail, just to make sure that there wasn't a hidden space somewhere that I was missing.
Then I thought maybe it had to do with the two SET commands being evaluated as part of the IF command, and maybe there was a problem with them, but if I remove the IF comparison, those commands work fine.
What am I missing here? The IF comparison is EXACTLY THE SAME!!! Why does the first example generate an error with that filename, but the second doesn't?
Again, because virtually EVERY SINGLE TIME I post a code snippet, someone points out that it doesn't do anything, let me again state: This is part of a much longer script. The rest of the script is not relevant to this problem. This is the part of the script that fails and what I've posted is enough to illustrate the problem. If I can't get this one part to work, worrying about the rest of the script is pointless.