Execution depends on what comes AFTER the line in question????????
Posted: 2022-Oct-12, 7:25 pm
OK, I'm at my wits end here. I'm trying to write a script that will pack ISO images to 7zip files. As part of that process, it detects whether the filename has "(Disc " in it, then it parses the filename to create a pattern that will find all the discs in that set and also what the highest number disc is, so that it can put that information in the archive name. At least that's what it's supposed to do.
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;
Obviously this doesn't do anything, but most importantly it doesn't generate an error! It executes PAUSE and then exits the routine.
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.
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;
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
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.